question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reset MDC TextField?

See original GitHub issue

Feature 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.

  1. 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');

  2. 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:open
  • Created 6 years ago
  • Reactions:5
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
Garbeecommented, Jul 10, 2017

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 a clear method given its context.

0reactions
patrickrodeecommented, Feb 14, 2020

Liz will investigate how this can be resolved to better cooperate with forms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MDC Reset - CodePen
1. // Update Form Fields & MDC reload (dummy data) ; 2. $('#updateFormValues').on("click", function(e) { ; 3. e.preventDefault(); ; 4 ; 5. let...
Read more >
MDC Components won't update UI when new values are added
MDC Components won't update UI when new values are added/ reset · click the UPDATE FORM VALUES button to add data · the...
Read more >
Text Field - Material Components for the Web
A text field doesn't require a label if a separate but clear label indicator is already displayed adjacent to the text field. Add...
Read more >
Auto Init - Material Design
Accessing the component instance · label class="mdc-text-field mdc-text-field--filled" data-mdc-auto-init="MDCTextField"> · span class="mdc-text-field__ripple"></ ...
Read more >
HTMLTextAreaElement - Web APIs | MDN
long: Returns / Sets the position of the element in the tabbing navigation order for the current document. ... string: Returns the string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found