material-design-lite: Dynamically changing input (.mdl-textfield) text with Javascript does not mark it as dirty
Demo: http://codepen.io/anon/pen/qdYEWw
Expected behavior: Clicking the button (and thus modifying the text) should add the is-dirty
class to the input’s parent, which would then move the label to the top of the input.
Actual behavior: Upon clicking the button, the input’s value changes, but the input’s parent is not marked as dirty, so the label appears on top of the input’s text.
Side note: I’ve had a lot of fun playing with this so far. Keep up the good work!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (2 by maintainers)
Commits related to this issue
- user can now forget hosts - hosts are never unpaired, so re-adding the hostname will not require pairing GFEHostIP field marked as `dirty` when mDNS found - thanks to https://github.com/google/materia... — committed to moonlight-stream/moonlight-chrome by raidancampbell 8 years ago
- Workaround for MDL Textfield bug https://github.com/google/material-design-lite/issues/903 https://github.com/google/material-design-lite/issues/4089 — committed to gabor-s/aurelia-mdl-dialog by gabor-s 7 years ago
- Workaround for MDL Textfield bug https://github.com/google/material-design-lite/issues/903 https://github.com/google/material-design-lite/issues/4089 — committed to gabor-s/aurelia-mdl-dialog by gabor-s 7 years ago
The is-dirty class is applied on the div that contains the textfield. So you need to apply this class on this div. Try it: http://codepen.io/anon/pen/EjRLVL
I came across this again. Something like below should work for everyone:
We don’t support react, but the PR was merged and the methods should be available in the current stable. To check dirty state after changing the value, call the
MaterialTextfield.checkDirty()
method against the node where the js class is assigned. For example:document.querySelector('mdl-js-textfield).MaterialTextfield.checkDirty()
.This still needs proper documenting before closing this issue out.
Add a unique class to all inputs that you need to check for dirty, select them all with
querySelectorAll
, then apply theMaterialTextfield.checkDirty()
method to each via a loop.You have to manually add the ‘is-dirty’ class to the parent, like this:
$(‘#sample3’).parent().addClass(‘is-dirty’);
Example: http://codepen.io/anon/pen/mVyzBr
This directive fix the is-dirty class missing on mdl-textfield__input http://stackoverflow.com/questions/31638890/mdl-textfield-not-taking-ngmodel-changes-into-account/40781433#40781433