-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mwc-textfield] Add a way to reset inputs state and value. #589
Comments
Two potential solutions could be a method to explicitly set the styled validity setValid(isValid: boolean): void; Or a more opinionated method to reset the UI's validity state. resetValidity(): void; |
Is |
That's a good point to talk about, but I would argue no. "Validity" in this sense is referring to UI validity styling, which is separate from a text field's "valid" or "invalid" state. That's why I'd go with something like reset() {
// native behavior, doesn't "empty" the field but returns to the initial value.
this.value = this.initialValue;
this.resetValidity();
} |
sidenote, there also seems to be an inconsistency between state of dom and // addclass
if (className === 'mdc-textfield--invalid') {
this.reportValidity();
} else {
this.mdcRoot.classList.add(className);
}
// removeClass
if (className === 'mdc-textfield--invalid') {
this.reportValidity();
} else {
this.mdcRoot.classList.remove(className);
} this tends to happen on |
@asyncLiz I agree
This request is originated from when one is emptying the value from the field. It's explicitly stated in the OP's code and as one of the end-users too I was requesting that feature for the same reason in another post. When one wants to just reset the validity of another form predicate he would usually use More but not least consider the simplification of subsequent code, just for instance : reset() {
this.form.querySelectorAll('mwc-textfield').forEach(textfield => textfield.reset());
} |
oops my bad, reopened |
This would cover all my uses cases. Additionally if all mwc form components had this interface it would make reseting inputs on a page trivial. |
This is also somewhat related to #289. If we implement form participation, resetting would be one of those facets. |
It's also necessary to reset selects, radio buttons, sliders, etc. |
AFAIK form participation is not in the plan for a while; mostly due to polyfilling issues. Instead we will be doing formdata event participation which I don't believe handles reset |
Same with <mwc-textfield type="number" .value="${this.value === 0 ? 0 : this.value || ''}"></mwc-textfield>
|
@masaoliou this is the intended behavior, when you type in the field you are not updating |
I inadvertently omitted the important part. The following version is more complete. <mwc-textfield type="number" .value="${this.value === 0 ? 0 : this.value || ''}" @change="${e=>this.value=e.target.value}"></mwc-textfield>
|
This is now added in the new text field, so going to close this issue as obsolete. |
** PLEASE READ THIS BEFORE FILING AN ISSUE **
I'm submitting a:
We would like a way to reset the mwc-textfield/textarea back to its default state clearing any validation error that might be shown.
We keep having to reach inside the input to remove the invalid state:
😱
The text was updated successfully, but these errors were encountered: