I need to disable Material Design Lite textfield via JS. I understand that I need to upgrade the element to MDL detects changes.
I expected that to be done like this:
$element.attr('disabled', 'disabled');
componentHandler.upgradeElement($element);
But that doesn't seem to work. I ended with this working solution:
$element.attr('disabled', 'disabled');
let inputWrap = $element.parent();
inputWrap.attr('data-upgraded', '');
inputWrap.attr('class', inputWrap.attr('class').replace(/is-upgraded/g, ''));
inputWrap.attr('class', inputWrap.attr('class').replace(/is-focused/g, ''));
componentHandler.upgradeElement(inputWrap[0]);
It did the trick but I can't shake the feeling that I am manually doing job for upgradeElement
function.
Is there a way to achieve this with less drastic approach? Any help would be much appreciated.