Allow validity message overriding for downstream i18n

This commit is contained in:
Talia 2025-01-27 16:22:13 +01:00
parent 6c3db0456e
commit 6cc5c43d82
2 changed files with 14 additions and 2 deletions

View file

@ -3,6 +3,6 @@
"browser": "src/BetterSelect.js",
"type": "module",
"license": "MIT",
"version": "1.5.0",
"version": "1.5.1",
"url": "https://darkwiiplayer.github.io/BetterSelect/"
}

View file

@ -446,13 +446,25 @@ export class BetterSelect extends HTMLElement {
set disabled(disabled) { this.toggleAttribute("disabled", 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() {
if (this.required) {
const valid = Boolean(this.value)
if (valid) {
this.#internals.setValidity({})
} else {
this.#internals.setValidity({valueMissing: true}, "Please select an option.")
this.#internals.setValidity({valueMissing: true}, this.validityMessage("valueMissing"))
}
return valid
} else {