-
Notifications
You must be signed in to change notification settings - Fork 896
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] validationMessage not set after calling reportValidaty() #971
Comments
We should discuss the built-in validity and how we want to handle it. |
It would be great if the mwc textfield would just work like native input fields and follow the validation API spec: I also did not manage to set constraints and make the appropriate message show up on validation (even though it is set in the nested input field). |
I agree! Our goal is to align as close to native as possible, including the constraint validation api. |
Just some more findings: |
For what it is worth, this is my textfield/textarea override for fetching native validation message when the field is invalid. /**
* mixin overrideing how mdc-textfiel handle validation message
* It gets native input validation message when
* no default validatationMessage is set.
*
* Related issue:
* https://github.com/material-components/material-components-web-components/issues/971
*
*/
export const TextFielValidityMessagedOverride = (baseElement) => class extends baseElement {
firstUpdated() {
if (this.validationMessage) {
this._initialValidationMessage = this.validationMessage;
}
super.firstUpdated();
}
reportValidity() {
const isValid = super.reportValidity();
// Note(cg): override validationMessage only if no initial message set.
if (!this._initialValidationMessage && !isValid) {
this.validationMessage = this.nativeValidationMessage;
}
return isValid;
}
get nativeValidationMessage() {
return this.formElement.validationMessage;
}
};
export default TextFielValidityMessagedOverride; |
I am the reporter of the issue #2365. For anyone who is encountering the same problem with a form jerk due to the missing helper/error markup, here's a quick hack I wrote to get around the issue. All I am doing is explicitly adding the same div after the input.
|
Fixed in M3 |
When calling reportValidity() on a mwc text field the validationMessage is empty.
The validationMessage is set on the native text input, but the message is not exposed be read from the text field.
The text was updated successfully, but these errors were encountered: