Reset MDC TextField?
See original GitHub issueFeature Requests
I opened this issue based on the request of @amsheehan on Discord.
I wanted to ask what’s the best way to reset MDC Input Fields after I typed into them? For example, I typed something and submitted that thing, I want that later, the MDC TextField to be reset and not have any text in it. I tried changing its value to ''
(none) and after that, I blur()
the field but it doesn’t work: the label doesn’t return to where it was but it keeps floating without any text.
-
UPDATE: I solved my problem by removing the
mdc-textfield__label--float-above
class from the label so it returns to where it was:document.querySelector('.label's class').classList.remove('mdc-textfield__label--float-above');
-
UPDATE: Another thing occurred when MDC TextField had a required attribute and turned red: the red input color didn’t go away so I did that:
document.querySelector('.mdc-textfield').classList.remove('mdc-textfield--invalid');
Maybe this could “be good to add to the component”: adding a function that fully resets MDC-Textfield!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:12 (12 by maintainers)
Top GitHub Comments
reset
is an actual thing too for HTML. There is a reset button type and form input method. These should be taken into account as well with the API for modifying the state of nodes.Depending on the context here,
reset
is actually what is desired. The example situation provided simply leans towards aclear
method given its context.Liz will investigate how this can be resolved to better cooperate with forms.