mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-25 07:47:55 +01:00
34 lines
981 B
JavaScript
34 lines
981 B
JavaScript
|
import {TextField as MWCTextField} from '@material/mwc-textfield';
|
||
|
|
||
|
export default class TextField extends MWCTextField {
|
||
|
get nativeValidationMessage() {
|
||
|
return this.formElement.validationMessage;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Fix mwc-textfield when handling validation message
|
||
|
* It gets native input validation message when no default validationMessage is set.
|
||
|
*
|
||
|
* Related issue:
|
||
|
* https://github.com/material-components/material-components-web-components/issues/971
|
||
|
*
|
||
|
*/
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.customElements.define('text-field', TextField);
|