From 6cc5c43d821c82d71c681831df4d20999a2dabb1 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 27 Jan 2025 16:22:13 +0100 Subject: [PATCH] Allow validity message overriding for downstream i18n --- package.json | 2 +- src/BetterSelect.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4b335b9..63532a1 100644 --- a/package.json +++ b/package.json @@ -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/" } diff --git a/src/BetterSelect.js b/src/BetterSelect.js index 032aaf5..5c13a0a 100644 --- a/src/BetterSelect.js +++ b/src/BetterSelect.js @@ -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 {