Allow validity message overriding for downstream i18n
This commit is contained in:
parent
6c3db0456e
commit
6cc5c43d82
2 changed files with 14 additions and 2 deletions
|
@ -3,6 +3,6 @@
|
||||||
"browser": "src/BetterSelect.js",
|
"browser": "src/BetterSelect.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "1.5.0",
|
"version": "1.5.1",
|
||||||
"url": "https://darkwiiplayer.github.io/BetterSelect/"
|
"url": "https://darkwiiplayer.github.io/BetterSelect/"
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,13 +446,25 @@ export class BetterSelect extends HTMLElement {
|
||||||
set disabled(disabled) { this.toggleAttribute("disabled", disabled) }
|
set disabled(disabled) { this.toggleAttribute("disabled", disabled) }
|
||||||
get disabled() { return this.hasAttribute("disabled") }
|
get disabled() { return this.hasAttribute("disabled") }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {"badInput"|"customError"|"patternMismatch"|"rangeOverflow"|"rangeUnderflow"|"stepMismatch"|"tooLong"|"tooShort"|"typeMismatch"|"valid"|"valueMissing"} ValidityConstraint
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ValidityConstraint} _constraint
|
||||||
|
*/
|
||||||
|
validityMessage(_constraint) {
|
||||||
|
return "Please select an option."
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setValidity() {
|
setValidity() {
|
||||||
if (this.required) {
|
if (this.required) {
|
||||||
const valid = Boolean(this.value)
|
const valid = Boolean(this.value)
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.#internals.setValidity({})
|
this.#internals.setValidity({})
|
||||||
} else {
|
} else {
|
||||||
this.#internals.setValidity({valueMissing: true}, "Please select an option.")
|
this.#internals.setValidity({valueMissing: true}, this.validityMessage("valueMissing"))
|
||||||
}
|
}
|
||||||
return valid
|
return valid
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue