diff --git a/CHANGELOG.md b/CHANGELOG.md index dd4a287..5b613ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* Use `Set.add` correctly + + *Sean Doyle* + ## 0.1.1 - 2024-09-27 * Expand version matrix to include `ruby@3.3` and `rails@7.2` diff --git a/app/assets/javascripts/constraint_validations.es.js b/app/assets/javascripts/constraint_validations.es.js index b659d2e..4148f09 100644 --- a/app/assets/javascripts/constraint_validations.es.js +++ b/app/assets/javascripts/constraint_validations.es.js @@ -161,7 +161,11 @@ function querySelectorAllNodes(selector, nodes, elements = new Set) { elements.add(node); } - elements.add(...querySelectorAllNodes(selector, node.children, elements)); + const childNodes = querySelectorAllNodes(selector, node.children, elements); + + for (const childNode of childNodes) { + elements.add(childNode); + } } } diff --git a/app/assets/javascripts/constraint_validations.es.js.map b/app/assets/javascripts/constraint_validations.es.js.map index 2b7deba..2a85270 100644 --- a/app/assets/javascripts/constraint_validations.es.js.map +++ b/app/assets/javascripts/constraint_validations.es.js.map @@ -1 +1 @@ -{"version":3,"file":"constraint_validations.es.js","sources":["../../javascript/constraint_validations/util.js","../../javascript/constraint_validations/validators/checkbox_validator.js","../../javascript/constraint_validations/index.js"],"sourcesContent":["export function isFieldElement(element) {\n return !element.disabled && \"validity\" in element && element.willValidate\n}\n\nexport function isAriaInvalid(element) {\n return element.getAttribute(\"aria-invalid\") === \"true\"\n}\n\nexport function readValidationMessages(input) {\n try {\n return JSON.parse(input.getAttribute(\"data-validation-messages\")) || {}\n } catch(_) {\n return {}\n }\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"../util\"\n\nexport default class {\n selector = \"input[type=checkbox]\"\n ignoringMutations = false\n\n constructor(constraintValidations, predicate) {\n this.constraintValidations = constraintValidations\n this.mutationObserver = new MutationObserver(this.handleMutation)\n this.enabled = typeof predicate === \"function\" ?\n predicate :\n (group) => !!predicate\n }\n\n connect() {\n this.element.addEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.observe(this.element, {\n attributeFilter: [\"required\"],\n childList: true,\n subtree: true\n })\n this.reportValidationMessages(this.element.querySelectorAll(this.selector), isAriaInvalid)\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.disconnect()\n }\n\n willValidate(target) {\n return this.willValidateGroup(checkboxGroup(target))\n }\n\n validate(target) {\n const checkboxesInGroup = checkboxGroup(target).filter(isCheckboxElement)\n const allRequired = checkboxesInGroup.every((checkbox) => isRequired(checkbox))\n const someChecked = checkboxesInGroup.some((checkbox) => checkbox.checked)\n\n if (allRequired && someChecked) {\n for (const checkbox of checkboxesInGroup) {\n this.constraintValidations.clearValidity(checkbox)\n }\n } else if (allRequired) {\n for (const checkbox of checkboxesInGroup) {\n const validationMessages = readValidationMessages(checkbox)\n\n checkbox.setCustomValidity(validationMessages.valueMissing)\n this.constraintValidations.reportValidity(checkbox)\n }\n }\n }\n\n // Private\n\n handleInvalid = ({ target }) => {\n const checkboxes = new Set\n\n for (const element of target.form.elements) {\n if (isCheckboxElement(element) && this.willValidate(element)) {\n checkboxes.add(element)\n }\n }\n\n this.reportValidationMessages(checkboxes)\n }\n\n handleMutation = (mutationRecords) => {\n if (this.ignoringMutations) return\n\n for (const { addedNodes, target, type } of mutationRecords) {\n if (type === \"attributes\") {\n if (target.required) {\n this.swapRequiredWithAriaRequired(target)\n } else {\n target.removeAttribute(\"aria-required\")\n }\n } else if (addedNodes.length) {\n this.reportValidationMessages(addedNodes, isAriaInvalid)\n }\n }\n }\n\n reportValidationMessages(nodes, willReport = () => true) {\n const requiredCheckboxes = querySelectorAllNodes(this.selector, nodes)\n\n for (const checkbox of requiredCheckboxes) {\n if (isRequired(checkbox)) {\n const group = checkboxGroup(checkbox)\n\n if (this.willValidateGroup(group)) {\n for (const checkboxInGroup of group) {\n this.swapRequiredWithAriaRequired(checkboxInGroup)\n\n if (willReport(checkboxInGroup)) {\n this.validate(checkboxInGroup)\n }\n }\n }\n }\n }\n }\n\n swapRequiredWithAriaRequired(element) {\n this.ignoringMutations = true\n element.required = false\n element.setAttribute(\"aria-required\", \"true\")\n setTimeout(() => this.ignoringMutations = false, 0)\n }\n\n willValidateGroup(group) {\n return group.length > 0 && this.enabled(group)\n }\n\n get element() {\n return this.constraintValidations.element\n }\n}\n\nfunction checkboxGroup(formControl) {\n const results = new Set\n const { name, form } = formControl\n\n if (name && form instanceof HTMLFormElement) {\n const group = form.elements.namedItem(name)\n const elements = Symbol.iterator in group ?\n group :\n [group]\n\n for (const element of elements) {\n if (element.type === \"checkbox\") {\n results.add(element)\n }\n }\n\n if (results.size === 1 && results.has(formControl)) {\n results.clear()\n }\n }\n\n return Array.from(results)\n}\n\nfunction querySelectorAllNodes(selector, nodes, elements = new Set) {\n for (const node of nodes) {\n if (node instanceof Element) {\n if (node.matches(selector)) {\n elements.add(node)\n }\n\n elements.add(...querySelectorAllNodes(selector, node.children, elements))\n }\n }\n\n return Array.from(elements)\n}\n\nfunction isCheckboxElement(element) {\n return isFieldElement(element) && element.type === \"checkbox\"\n}\n\nfunction isRequired(element) {\n return element.required || element.getAttribute(\"aria-required\") === \"true\"\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"./util\"\nimport CheckboxValidator from \"./validators/checkbox_validator\"\n\nconst defaultOptions = {\n disableSubmitWhenInvalid: false,\n validateOn: [\"blur\", \"input\"],\n validators: {\n checkbox: false\n }\n}\n\nexport default class ConstraintValidations {\n static connect(element = document, options = {}) {\n new this(element, options).connect()\n }\n\n constructor(element = document, options = {}) {\n this.element = element\n this.options = { ...defaultOptions, ...options }\n this.validators = [\n new CheckboxValidator(this, this.options.validators.checkbox)\n ]\n }\n\n connect() {\n this.validators.forEach(validator => validator.connect())\n this.element.addEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.addEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.addEventListener(\"input\", this.toggleSubmitsDisabled)\n\n this.reportValidationMessages(\n this.element instanceof HTMLFormElement ?\n [this.element] :\n this.element.querySelectorAll(\"form\")\n )\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.removeEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.removeEventListener(\"input\", this.toggleSubmitsDisabled)\n this.validators.forEach(validator => validator.disconnect())\n }\n\n reportFieldValidity = (event) => {\n if (isFieldElement(event.target) && this.reportValidity(event.target)) {\n event.preventDefault()\n\n focusFirstInvalidField(event.target.form || event.target)\n }\n }\n\n clearAndReportFieldValidity = ({ target }) => {\n if (isFieldElement(target)) {\n this.clearValidity(target)\n\n for (const validator of this.validators) {\n if (validator.willValidate(target)) {\n validator.validate(target)\n }\n }\n\n this.reportValidity(target)\n }\n }\n\n toggleSubmitsDisabled = ({ target }) => {\n if (isFieldElement(target) && this.willDisableSubmitWhenInvalid(target)) {\n disableSubmitWhenInvalid(target.form)\n }\n }\n\n reportValidationMessages(forms) {\n const invalidFields = []\n\n for (const form of forms) {\n for (const element of Array.from(form.elements).filter(isFieldElement)) {\n const serverRenderedInvalid = isAriaInvalid(element)\n const id = element.getAttribute(\"aria-errormessage\")\n const errorMessageElement = document.getElementById(id)\n const validationMessage = errorMessageElement?.textContent\n\n if (validationMessage) {\n element.setCustomValidity(validationMessage)\n }\n\n if (validationMessage || serverRenderedInvalid) {\n this.reportValidity(element)\n invalidFields.push(element)\n }\n\n if (this.willDisableSubmitWhenInvalid(element)) {\n disableSubmitWhenInvalid(form)\n }\n }\n }\n\n const [firstInvalidField] = invalidFields\n firstInvalidField?.focus()\n }\n\n willDisableSubmitWhenInvalid(target) {\n return typeof this.options.disableSubmitWhenInvalid === \"function\" ?\n this.options.disableSubmitWhenInvalid(target) :\n !!this.options.disableSubmitWhenInvalid\n }\n\n clearValidity(input) {\n input.setCustomValidity(\"\")\n\n this.reportValidity(input)\n }\n\n reportValidity(input) {\n const id = input.getAttribute(\"aria-errormessage\")\n const validationMessage = getValidationMessage(input)\n const element = document.getElementById(id) || createValidationMessageFragment(input.form)\n\n if (input.form?.noValidate) {\n return false\n } else if (id && element) {\n element.id = id\n element.innerHTML = validationMessage\n\n if (validationMessage) {\n input.setCustomValidity(validationMessage)\n input.setAttribute(\"aria-describedby\", id)\n input.setAttribute(\"aria-invalid\", \"true\")\n } else {\n input.removeAttribute(\"aria-describedby\")\n input.removeAttribute(\"aria-invalid\")\n }\n\n if (!element.parentElement) {\n input.insertAdjacentElement(\"afterend\", element)\n }\n\n if (input.form && this.willDisableSubmitWhenInvalid(input)) disableSubmitWhenInvalid(input.form)\n\n return true\n } else {\n return false\n }\n }\n}\n\nfunction focusFirstInvalidField(element) {\n if (element instanceof HTMLFormElement) {\n return Array.from(element.elements).some(field => focusFirstInvalidField(field))\n } else if (isFieldElement(element) && !element.validity.valid) {\n element.focus()\n element.scrollIntoView()\n return true\n } else {\n return false\n }\n}\n\nfunction disableSubmitWhenInvalid(form) {\n if (!form || form.noValidate) return\n\n const isValid = Array.from(form.elements).filter(isFieldElement).every(input => input.validity.valid)\n\n for (const element of form.elements) {\n if (element.type == \"submit\" && !element.formNoValidate) {\n element.disabled = !isValid\n }\n }\n}\n\nfunction createValidationMessageFragment(form) {\n if (form) {\n const template = form.querySelector(\"[data-validation-message-template]\")\n\n return template?.content.children[0].cloneNode()\n }\n}\n\nfunction getValidationMessage(input) {\n const validationMessages = Object.entries(readValidationMessages(input))\n\n const [ _, validationMessage ] = validationMessages.find(([ key ]) => input.validity[key]) || [ null, null ]\n\n return validationMessage || input.validationMessage\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,CAAC,OAAO,EAAE;AACxC,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,UAAU,IAAI,OAAO,IAAI,OA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AAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE;AAC9G;AACA,EAAE,OAAO,iBAAiB,IAAI,KAAK,CAAC,iBAAiB;AACrD;;;;"} \ No newline at end of file +{"version":3,"file":"constraint_validations.es.js","sources":["../../javascript/constraint_validations/util.js","../../javascript/constraint_validations/validators/checkbox_validator.js","../../javascript/constraint_validations/index.js"],"sourcesContent":["export function isFieldElement(element) {\n return !element.disabled && \"validity\" in element && element.willValidate\n}\n\nexport function isAriaInvalid(element) {\n return element.getAttribute(\"aria-invalid\") === \"true\"\n}\n\nexport function readValidationMessages(input) {\n try {\n return JSON.parse(input.getAttribute(\"data-validation-messages\")) || {}\n } catch(_) {\n return {}\n }\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"../util\"\n\nexport default class {\n selector = \"input[type=checkbox]\"\n ignoringMutations = false\n\n constructor(constraintValidations, predicate) {\n this.constraintValidations = constraintValidations\n this.mutationObserver = new MutationObserver(this.handleMutation)\n this.enabled = typeof predicate === \"function\" ?\n predicate :\n (group) => !!predicate\n }\n\n connect() {\n this.element.addEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.observe(this.element, {\n attributeFilter: [\"required\"],\n childList: true,\n subtree: true\n })\n this.reportValidationMessages(this.element.querySelectorAll(this.selector), isAriaInvalid)\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.disconnect()\n }\n\n willValidate(target) {\n return this.willValidateGroup(checkboxGroup(target))\n }\n\n validate(target) {\n const checkboxesInGroup = checkboxGroup(target).filter(isCheckboxElement)\n const allRequired = checkboxesInGroup.every((checkbox) => isRequired(checkbox))\n const someChecked = checkboxesInGroup.some((checkbox) => checkbox.checked)\n\n if (allRequired && someChecked) {\n for (const checkbox of checkboxesInGroup) {\n this.constraintValidations.clearValidity(checkbox)\n }\n } else if (allRequired) {\n for (const checkbox of checkboxesInGroup) {\n const validationMessages = readValidationMessages(checkbox)\n\n checkbox.setCustomValidity(validationMessages.valueMissing)\n this.constraintValidations.reportValidity(checkbox)\n }\n }\n }\n\n // Private\n\n handleInvalid = ({ target }) => {\n const checkboxes = new Set\n\n for (const element of target.form.elements) {\n if (isCheckboxElement(element) && this.willValidate(element)) {\n checkboxes.add(element)\n }\n }\n\n this.reportValidationMessages(checkboxes)\n }\n\n handleMutation = (mutationRecords) => {\n if (this.ignoringMutations) return\n\n for (const { addedNodes, target, type } of mutationRecords) {\n if (type === \"attributes\") {\n if (target.required) {\n this.swapRequiredWithAriaRequired(target)\n } else {\n target.removeAttribute(\"aria-required\")\n }\n } else if (addedNodes.length) {\n this.reportValidationMessages(addedNodes, isAriaInvalid)\n }\n }\n }\n\n reportValidationMessages(nodes, willReport = () => true) {\n const requiredCheckboxes = querySelectorAllNodes(this.selector, nodes)\n\n for (const checkbox of requiredCheckboxes) {\n if (isRequired(checkbox)) {\n const group = checkboxGroup(checkbox)\n\n if (this.willValidateGroup(group)) {\n for (const checkboxInGroup of group) {\n this.swapRequiredWithAriaRequired(checkboxInGroup)\n\n if (willReport(checkboxInGroup)) {\n this.validate(checkboxInGroup)\n }\n }\n }\n }\n }\n }\n\n swapRequiredWithAriaRequired(element) {\n this.ignoringMutations = true\n element.required = false\n element.setAttribute(\"aria-required\", \"true\")\n setTimeout(() => this.ignoringMutations = false, 0)\n }\n\n willValidateGroup(group) {\n return group.length > 0 && this.enabled(group)\n }\n\n get element() {\n return this.constraintValidations.element\n }\n}\n\nfunction checkboxGroup(formControl) {\n const results = new Set\n const { name, form } = formControl\n\n if (name && form instanceof HTMLFormElement) {\n const group = form.elements.namedItem(name)\n const elements = Symbol.iterator in group ?\n group :\n [group]\n\n for (const element of elements) {\n if (element.type === \"checkbox\") {\n results.add(element)\n }\n }\n\n if (results.size === 1 && results.has(formControl)) {\n results.clear()\n }\n }\n\n return Array.from(results)\n}\n\nfunction querySelectorAllNodes(selector, nodes, elements = new Set) {\n for (const node of nodes) {\n if (node instanceof Element) {\n if (node.matches(selector)) {\n elements.add(node)\n }\n\n const childNodes = querySelectorAllNodes(selector, node.children, elements)\n\n for (const childNode of childNodes) {\n elements.add(childNode)\n }\n }\n }\n\n return Array.from(elements)\n}\n\nfunction isCheckboxElement(element) {\n return isFieldElement(element) && element.type === \"checkbox\"\n}\n\nfunction isRequired(element) {\n return element.required || element.getAttribute(\"aria-required\") === \"true\"\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"./util\"\nimport CheckboxValidator from \"./validators/checkbox_validator\"\n\nconst defaultOptions = {\n disableSubmitWhenInvalid: false,\n validateOn: [\"blur\", \"input\"],\n validators: {\n checkbox: false\n }\n}\n\nexport default class ConstraintValidations {\n static connect(element = document, options = {}) {\n new this(element, options).connect()\n }\n\n constructor(element = document, options = {}) {\n this.element = element\n this.options = { ...defaultOptions, ...options }\n this.validators = [\n new CheckboxValidator(this, this.options.validators.checkbox)\n ]\n }\n\n connect() {\n this.validators.forEach(validator => validator.connect())\n this.element.addEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.addEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.addEventListener(\"input\", this.toggleSubmitsDisabled)\n\n this.reportValidationMessages(\n this.element instanceof HTMLFormElement ?\n [this.element] :\n this.element.querySelectorAll(\"form\")\n )\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.removeEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.removeEventListener(\"input\", this.toggleSubmitsDisabled)\n this.validators.forEach(validator => validator.disconnect())\n }\n\n reportFieldValidity = (event) => {\n if (isFieldElement(event.target) && this.reportValidity(event.target)) {\n event.preventDefault()\n\n focusFirstInvalidField(event.target.form || event.target)\n }\n }\n\n clearAndReportFieldValidity = ({ target }) => {\n if (isFieldElement(target)) {\n this.clearValidity(target)\n\n for (const validator of this.validators) {\n if (validator.willValidate(target)) {\n validator.validate(target)\n }\n }\n\n this.reportValidity(target)\n }\n }\n\n toggleSubmitsDisabled = ({ target }) => {\n if (isFieldElement(target) && this.willDisableSubmitWhenInvalid(target)) {\n disableSubmitWhenInvalid(target.form)\n }\n }\n\n reportValidationMessages(forms) {\n const invalidFields = []\n\n for (const form of forms) {\n for (const element of Array.from(form.elements).filter(isFieldElement)) {\n const serverRenderedInvalid = isAriaInvalid(element)\n const id = element.getAttribute(\"aria-errormessage\")\n const errorMessageElement = document.getElementById(id)\n const validationMessage = errorMessageElement?.textContent\n\n if (validationMessage) {\n element.setCustomValidity(validationMessage)\n }\n\n if (validationMessage || serverRenderedInvalid) {\n this.reportValidity(element)\n invalidFields.push(element)\n }\n\n if (this.willDisableSubmitWhenInvalid(element)) {\n disableSubmitWhenInvalid(form)\n }\n }\n }\n\n const [firstInvalidField] = invalidFields\n firstInvalidField?.focus()\n }\n\n willDisableSubmitWhenInvalid(target) {\n return typeof this.options.disableSubmitWhenInvalid === \"function\" ?\n this.options.disableSubmitWhenInvalid(target) :\n !!this.options.disableSubmitWhenInvalid\n }\n\n clearValidity(input) {\n input.setCustomValidity(\"\")\n\n this.reportValidity(input)\n }\n\n reportValidity(input) {\n const id = input.getAttribute(\"aria-errormessage\")\n const validationMessage = getValidationMessage(input)\n const element = document.getElementById(id) || createValidationMessageFragment(input.form)\n\n if (input.form?.noValidate) {\n return false\n } else if (id && element) {\n element.id = id\n element.innerHTML = validationMessage\n\n if (validationMessage) {\n input.setCustomValidity(validationMessage)\n input.setAttribute(\"aria-describedby\", id)\n input.setAttribute(\"aria-invalid\", \"true\")\n } else {\n input.removeAttribute(\"aria-describedby\")\n input.removeAttribute(\"aria-invalid\")\n }\n\n if (!element.parentElement) {\n input.insertAdjacentElement(\"afterend\", element)\n }\n\n if (input.form && this.willDisableSubmitWhenInvalid(input)) disableSubmitWhenInvalid(input.form)\n\n return true\n } else {\n return false\n }\n }\n}\n\nfunction focusFirstInvalidField(element) {\n if (element instanceof HTMLFormElement) {\n return Array.from(element.elements).some(field => focusFirstInvalidField(field))\n } else if (isFieldElement(element) && !element.validity.valid) {\n element.focus()\n element.scrollIntoView()\n return true\n } else {\n return false\n }\n}\n\nfunction disableSubmitWhenInvalid(form) {\n if (!form || form.noValidate) return\n\n const isValid = Array.from(form.elements).filter(isFieldElement).every(input => input.validity.valid)\n\n for (const element of form.elements) {\n if (element.type == \"submit\" && !element.formNoValidate) {\n element.disabled = !isValid\n }\n }\n}\n\nfunction createValidationMessageFragment(form) {\n if (form) {\n const template = form.querySelector(\"[data-validation-message-template]\")\n\n return template?.content.children[0].cloneNode()\n }\n}\n\nfunction getValidationMessage(input) {\n const validationMessages = Object.entries(readValidationMessages(input))\n\n const [ _, validationMessage ] = validationMessages.find(([ key ]) => input.validity[key]) || [ null, null ]\n\n return validationMessage || input.validationMessage\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,CAAC,OAAO,EAAE;AACxC,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,UAAU,IAAI,OAAO,IAAI,OAAO,CAAC,YAAY;AAC3E,CAAC;AACD;AACO,SAAS,aAAa,CAAC,OAAO,EAAE;AACvC,EAAE,OAAO,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,MAAM;AACxD,CAAC;AACD;AACO,SAAS,sBAAsB,CAAC,KAAK,EAAE;AAC9C,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAAC,IAAI,EAAE;AAC3E,GAAG,CAAC,MAAM,CAAC,EAAE;AACb,IAAI,OAAO,EAAE;AACb,GAAG;AACH;;ACZe,uBAAK,CAAC;AACrB,EAAE,QAAQ,GAAG,sBAAsB;AACnC,EAAE,iBAAiB,GAAG,KAAK;AAC3B;AACA,EAAE,WAAW,CAAC,qBAAqB,EAAE,S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,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAC;AACvG;AACA,EAAE,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvC,IAAI,IAAI,OAAO,CAAC,IAAI,IAAI,QAAQ,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;AAC7D,MAAM,OAAO,CAAC,QAAQ,GAAG,CAAC,QAAO;AACjC,KAAK;AACL,GAAG;AACH,CAAC;AACD;AACA,SAAS,+BAA+B,CAAC,IAAI,EAAE;AAC/C,EAAE,IAAI,IAAI,EAAE;AACZ,IAAI,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,oCAAoC,EAAC;AAC7E;AACA,IAAI,OAAO,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE;AACpD,GAAG;AACH,CAAC;AACD;AACA,SAAS,oBAAoB,CAAC,KAAK,EAAE;AACrC,EAAE,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAC;AAC1E;AACA,EAAE,MAAM,EAAE,CAAC,EAAE,iBAAiB,EAAE,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE;AAC9G;AACA,EAAE,OAAO,iBAAiB,IAAI,KAAK,CAAC,iBAAiB;AACrD;;;;"} \ No newline at end of file diff --git a/app/assets/javascripts/constraint_validations.js b/app/assets/javascripts/constraint_validations.js index 9ae99df..dcfbdb3 100644 --- a/app/assets/javascripts/constraint_validations.js +++ b/app/assets/javascripts/constraint_validations.js @@ -134,7 +134,10 @@ var ConstraintValidations = function() { if (node.matches(selector)) { elements.add(node); } - elements.add(...querySelectorAllNodes(selector, node.children, elements)); + const childNodes = querySelectorAllNodes(selector, node.children, elements); + for (const childNode of childNodes) { + elements.add(childNode); + } } } return Array.from(elements); diff --git a/app/assets/javascripts/constraint_validations.js.map b/app/assets/javascripts/constraint_validations.js.map index be0fb0f..febcfd1 100644 --- a/app/assets/javascripts/constraint_validations.js.map +++ b/app/assets/javascripts/constraint_validations.js.map @@ -1 +1 @@ -{"version":3,"file":"constraint_validations.js","sources":["../../javascript/constraint_validations/util.js","../../javascript/constraint_validations/validators/checkbox_validator.js","../../javascript/constraint_validations/index.js"],"sourcesContent":["export function isFieldElement(element) {\n return !element.disabled && \"validity\" in element && element.willValidate\n}\n\nexport function isAriaInvalid(element) {\n return element.getAttribute(\"aria-invalid\") === \"true\"\n}\n\nexport function readValidationMessages(input) {\n try {\n return JSON.parse(input.getAttribute(\"data-validation-messages\")) || {}\n } catch(_) {\n return {}\n }\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"../util\"\n\nexport default class {\n selector = \"input[type=checkbox]\"\n ignoringMutations = false\n\n constructor(constraintValidations, predicate) {\n this.constraintValidations = constraintValidations\n this.mutationObserver = new MutationObserver(this.handleMutation)\n this.enabled = typeof predicate === \"function\" ?\n predicate :\n (group) => !!predicate\n }\n\n connect() {\n this.element.addEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.observe(this.element, {\n attributeFilter: [\"required\"],\n childList: true,\n subtree: true\n })\n this.reportValidationMessages(this.element.querySelectorAll(this.selector), isAriaInvalid)\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.disconnect()\n }\n\n willValidate(target) {\n return this.willValidateGroup(checkboxGroup(target))\n }\n\n validate(target) {\n const checkboxesInGroup = checkboxGroup(target).filter(isCheckboxElement)\n const allRequired = checkboxesInGroup.every((checkbox) => isRequired(checkbox))\n const someChecked = checkboxesInGroup.some((checkbox) => checkbox.checked)\n\n if (allRequired && someChecked) {\n for (const checkbox of checkboxesInGroup) {\n this.constraintValidations.clearValidity(checkbox)\n }\n } else if (allRequired) {\n for (const checkbox of checkboxesInGroup) {\n const validationMessages = readValidationMessages(checkbox)\n\n checkbox.setCustomValidity(validationMessages.valueMissing)\n this.constraintValidations.reportValidity(checkbox)\n }\n }\n }\n\n // Private\n\n handleInvalid = ({ target }) => {\n const checkboxes = new Set\n\n for (const element of target.form.elements) {\n if (isCheckboxElement(element) && this.willValidate(element)) {\n checkboxes.add(element)\n }\n }\n\n this.reportValidationMessages(checkboxes)\n }\n\n handleMutation = (mutationRecords) => {\n if (this.ignoringMutations) return\n\n for (const { addedNodes, target, type } of mutationRecords) {\n if (type === \"attributes\") {\n if (target.required) {\n this.swapRequiredWithAriaRequired(target)\n } else {\n target.removeAttribute(\"aria-required\")\n }\n } else if (addedNodes.length) {\n this.reportValidationMessages(addedNodes, isAriaInvalid)\n }\n }\n }\n\n reportValidationMessages(nodes, willReport = () => true) {\n const requiredCheckboxes = querySelectorAllNodes(this.selector, nodes)\n\n for (const checkbox of requiredCheckboxes) {\n if (isRequired(checkbox)) {\n const group = checkboxGroup(checkbox)\n\n if (this.willValidateGroup(group)) {\n for (const checkboxInGroup of group) {\n this.swapRequiredWithAriaRequired(checkboxInGroup)\n\n if (willReport(checkboxInGroup)) {\n this.validate(checkboxInGroup)\n }\n }\n }\n }\n }\n }\n\n swapRequiredWithAriaRequired(element) {\n this.ignoringMutations = true\n element.required = false\n element.setAttribute(\"aria-required\", \"true\")\n setTimeout(() => this.ignoringMutations = false, 0)\n }\n\n willValidateGroup(group) {\n return group.length > 0 && this.enabled(group)\n }\n\n get element() {\n return this.constraintValidations.element\n }\n}\n\nfunction checkboxGroup(formControl) {\n const results = new Set\n const { name, form } = formControl\n\n if (name && form instanceof HTMLFormElement) {\n const group = form.elements.namedItem(name)\n const elements = Symbol.iterator in group ?\n group :\n [group]\n\n for (const element of elements) {\n if (element.type === \"checkbox\") {\n results.add(element)\n }\n }\n\n if (results.size === 1 && results.has(formControl)) {\n results.clear()\n }\n }\n\n return Array.from(results)\n}\n\nfunction querySelectorAllNodes(selector, nodes, elements = new Set) {\n for (const node of nodes) {\n if (node instanceof Element) {\n if (node.matches(selector)) {\n elements.add(node)\n }\n\n elements.add(...querySelectorAllNodes(selector, node.children, elements))\n }\n }\n\n return Array.from(elements)\n}\n\nfunction isCheckboxElement(element) {\n return isFieldElement(element) && element.type === \"checkbox\"\n}\n\nfunction isRequired(element) {\n return element.required || element.getAttribute(\"aria-required\") === \"true\"\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"./util\"\nimport CheckboxValidator from \"./validators/checkbox_validator\"\n\nconst defaultOptions = {\n disableSubmitWhenInvalid: false,\n validateOn: [\"blur\", \"input\"],\n validators: {\n checkbox: false\n }\n}\n\nexport default class ConstraintValidations {\n static connect(element = document, options = {}) {\n new this(element, options).connect()\n }\n\n constructor(element = document, options = {}) {\n this.element = element\n this.options = { ...defaultOptions, ...options }\n this.validators = [\n new CheckboxValidator(this, this.options.validators.checkbox)\n ]\n }\n\n connect() {\n this.validators.forEach(validator => validator.connect())\n this.element.addEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.addEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.addEventListener(\"input\", this.toggleSubmitsDisabled)\n\n this.reportValidationMessages(\n this.element instanceof HTMLFormElement ?\n [this.element] :\n this.element.querySelectorAll(\"form\")\n )\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.removeEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.removeEventListener(\"input\", this.toggleSubmitsDisabled)\n this.validators.forEach(validator => validator.disconnect())\n }\n\n reportFieldValidity = (event) => {\n if (isFieldElement(event.target) && this.reportValidity(event.target)) {\n event.preventDefault()\n\n focusFirstInvalidField(event.target.form || event.target)\n }\n }\n\n clearAndReportFieldValidity = ({ target }) => {\n if (isFieldElement(target)) {\n this.clearValidity(target)\n\n for (const validator of this.validators) {\n if (validator.willValidate(target)) {\n validator.validate(target)\n }\n }\n\n this.reportValidity(target)\n }\n }\n\n toggleSubmitsDisabled = ({ target }) => {\n if (isFieldElement(target) && this.willDisableSubmitWhenInvalid(target)) {\n disableSubmitWhenInvalid(target.form)\n }\n }\n\n reportValidationMessages(forms) {\n const invalidFields = []\n\n for (const form of forms) {\n for (const element of Array.from(form.elements).filter(isFieldElement)) {\n const serverRenderedInvalid = isAriaInvalid(element)\n const id = element.getAttribute(\"aria-errormessage\")\n const errorMessageElement = document.getElementById(id)\n const validationMessage = errorMessageElement?.textContent\n\n if (validationMessage) {\n element.setCustomValidity(validationMessage)\n }\n\n if (validationMessage || serverRenderedInvalid) {\n this.reportValidity(element)\n invalidFields.push(element)\n }\n\n if (this.willDisableSubmitWhenInvalid(element)) {\n disableSubmitWhenInvalid(form)\n }\n }\n }\n\n const [firstInvalidField] = invalidFields\n firstInvalidField?.focus()\n }\n\n willDisableSubmitWhenInvalid(target) {\n return typeof this.options.disableSubmitWhenInvalid === \"function\" ?\n this.options.disableSubmitWhenInvalid(target) :\n !!this.options.disableSubmitWhenInvalid\n }\n\n clearValidity(input) {\n input.setCustomValidity(\"\")\n\n this.reportValidity(input)\n }\n\n reportValidity(input) {\n const id = input.getAttribute(\"aria-errormessage\")\n const validationMessage = getValidationMessage(input)\n const element = document.getElementById(id) || createValidationMessageFragment(input.form)\n\n if (input.form?.noValidate) {\n return false\n } else if (id && element) {\n element.id = id\n element.innerHTML = validationMessage\n\n if (validationMessage) {\n input.setCustomValidity(validationMessage)\n input.setAttribute(\"aria-describedby\", id)\n input.setAttribute(\"aria-invalid\", \"true\")\n } else {\n input.removeAttribute(\"aria-describedby\")\n input.removeAttribute(\"aria-invalid\")\n }\n\n if (!element.parentElement) {\n input.insertAdjacentElement(\"afterend\", element)\n }\n\n if (input.form && this.willDisableSubmitWhenInvalid(input)) disableSubmitWhenInvalid(input.form)\n\n return true\n } else {\n return false\n }\n }\n}\n\nfunction focusFirstInvalidField(element) {\n if (element instanceof HTMLFormElement) {\n return Array.from(element.elements).some(field => focusFirstInvalidField(field))\n } else if (isFieldElement(element) && !element.validity.valid) {\n element.focus()\n element.scrollIntoView()\n return true\n } else {\n return false\n }\n}\n\nfunction disableSubmitWhenInvalid(form) {\n if (!form || form.noValidate) return\n\n const isValid = Array.from(form.elements).filter(isFieldElement).every(input => input.validity.valid)\n\n for (const element of form.elements) {\n if (element.type == \"submit\" && !element.formNoValidate) {\n element.disabled = !isValid\n }\n }\n}\n\nfunction createValidationMessageFragment(form) {\n if (form) {\n const template = form.querySelector(\"[data-validation-message-template]\")\n\n return template?.content.children[0].cloneNode()\n }\n}\n\nfunction getValidationMessage(input) {\n const validationMessages = Object.entries(readValidationMessages(input))\n\n const [ _, validationMessage ] = validationMessages.find(([ key ]) => input.validity[key]) || [ null, null ]\n\n return validationMessage || input.validationMessage\n}\n"],"names":["isFieldElement","element","disabled","willValidate","isAriaInvalid","getAttribute","readValidationMessages","input","JSON","parse","_","[object Object]","constraintValidations","predicate","this","mutationObserver","MutationObserver","handleMutation","enabled","group","addEventListener","handleInvalid","capture","passive","observe","attributeFilter","childList","subtree","reportValidationMessages","querySelectorAll","selector","removeEventListener","disconnect","target","willValidateGroup","checkboxGroup","checkboxesInGroup","filter","isCheckboxElement","allRequired","every","checkbox","isRequired","someChecked","some","checked","clearValidity","validationMessages","setCustomValidity","valueMissing","reportValidity","checkboxes","Set","form","elements","add","mutationRecords","ignoringMutations","addedNodes","type","required","swapRequiredWithAriaRequired","removeAttribute","length","nodes","willReport","requiredCheckboxes","querySelectorAllNodes","checkboxInGroup","validate","setAttribute","setTimeout","formControl","results","name","HTMLFormElement","namedItem","Symbol","iterator","size","has","clear","Array","from","node","Element","matches","children","defaultOptions","disableSubmitWhenInvalid","validateOn","validators","ConstraintValidations","document","options","connect","CheckboxValidator","forEach","validator","reportFieldValidity","eventName","clearAndReportFieldValidity","toggleSubmitsDisabled","event","preventDefault","focusFirstInvalidField","willDisableSubmitWhenInvalid","forms","invalidFields","serverRenderedInvalid","id","errorMessageElement","getElementById","validationMessage","textContent","push","firstInvalidField","focus","getValidationMessage","createValidationMessageFragment","noValidate","innerHTML","parentElement","insertAdjacentElement","field","validity","valid","scrollIntoView","isValid","formNoValidate","template","querySelector","content","cloneNode","Object","entries","find","key"],"mappings":";;EAAO,SAASA,eAAeC;IAC7B,QAAQA,QAAQC,YAAY,cAAcD,WAAWA,QAAQE;;EAGxD,SAASC,cAAcH;IAC5B,OAAOA,QAAQI,aAAa,oBAAoB;;EAG3C,SAASC,uBAAuBC;IACrC;MACE,OAAOC,KAAKC,MAAMF,MAAMF,aAAa,gCAAgC;MACrE,OAAMK;MACN,OAAO;;;ECVI;IACbC,SAAW;IACXA,kBAAoB;IAEpBA,YAAYC,uBAAuBC;MACjCC,KAAKF,wBAAwBA;MAC7BE,KAAKC,mBAAmB,IAAIC,iBAAiBF,KAAKG;MAClDH,KAAKI,iBAAiBL,cAAc,aAClCA,YACCM,WAAYN;;IAGjBF;MACEG,KAAKb,QAAQmB,iBAAiB,WAAWN,KAAKO,eAAe;QAAEC,SAAS;QAAMC,SAAS;;MACvFT,KAAKC,iBAAiBS,QAAQV,KAAKb,SAAS;QAC1CwB,iBAAiB,EAAC;QAClBC,WAAW;QACXC,SAAS;;MAEXb,KAAKc,yBAAyBd,KAAKb,QAAQ4B,iBAAiBf,KAAKgB,WAAW1B;;IAG9EO;MACEG,KAAKb,QAAQ8B,oBAAoB,WAAWjB,KAAKO,eAAe;QAAEC,SAAS;QAAMC,SAAS;;MAC1FT,KAAKC,iBAAiBiB;;IAGxBrB,aAAasB;MACX,OAAOnB,KAAKoB,kBAAkBC,cAAcF;;IAG9CtB,SAASsB;MACP,MAAMG,oBAAoBD,cAAcF,QAAQI,OAAOC;MACvD,MAAMC,cAAcH,kBAAkBI,OAAOC,YAAaC,WAAWD;MACrE,MAAME,cAAcP,kBAAkBQ,MAAMH,YA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":["../../javascript/constraint_validations/util.js","../../javascript/constraint_validations/validators/checkbox_validator.js","../../javascript/constraint_validations/index.js"],"sourcesContent":["export function isFieldElement(element) {\n return !element.disabled && \"validity\" in element && element.willValidate\n}\n\nexport function isAriaInvalid(element) {\n return element.getAttribute(\"aria-invalid\") === \"true\"\n}\n\nexport function readValidationMessages(input) {\n try {\n return JSON.parse(input.getAttribute(\"data-validation-messages\")) || {}\n } catch(_) {\n return {}\n }\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"../util\"\n\nexport default class {\n selector = \"input[type=checkbox]\"\n ignoringMutations = false\n\n constructor(constraintValidations, predicate) {\n this.constraintValidations = constraintValidations\n this.mutationObserver = new MutationObserver(this.handleMutation)\n this.enabled = typeof predicate === \"function\" ?\n predicate :\n (group) => !!predicate\n }\n\n connect() {\n this.element.addEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.observe(this.element, {\n attributeFilter: [\"required\"],\n childList: true,\n subtree: true\n })\n this.reportValidationMessages(this.element.querySelectorAll(this.selector), isAriaInvalid)\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.handleInvalid, { capture: true, passive: true })\n this.mutationObserver.disconnect()\n }\n\n willValidate(target) {\n return this.willValidateGroup(checkboxGroup(target))\n }\n\n validate(target) {\n const checkboxesInGroup = checkboxGroup(target).filter(isCheckboxElement)\n const allRequired = checkboxesInGroup.every((checkbox) => isRequired(checkbox))\n const someChecked = checkboxesInGroup.some((checkbox) => checkbox.checked)\n\n if (allRequired && someChecked) {\n for (const checkbox of checkboxesInGroup) {\n this.constraintValidations.clearValidity(checkbox)\n }\n } else if (allRequired) {\n for (const checkbox of checkboxesInGroup) {\n const validationMessages = readValidationMessages(checkbox)\n\n checkbox.setCustomValidity(validationMessages.valueMissing)\n this.constraintValidations.reportValidity(checkbox)\n }\n }\n }\n\n // Private\n\n handleInvalid = ({ target }) => {\n const checkboxes = new Set\n\n for (const element of target.form.elements) {\n if (isCheckboxElement(element) && this.willValidate(element)) {\n checkboxes.add(element)\n }\n }\n\n this.reportValidationMessages(checkboxes)\n }\n\n handleMutation = (mutationRecords) => {\n if (this.ignoringMutations) return\n\n for (const { addedNodes, target, type } of mutationRecords) {\n if (type === \"attributes\") {\n if (target.required) {\n this.swapRequiredWithAriaRequired(target)\n } else {\n target.removeAttribute(\"aria-required\")\n }\n } else if (addedNodes.length) {\n this.reportValidationMessages(addedNodes, isAriaInvalid)\n }\n }\n }\n\n reportValidationMessages(nodes, willReport = () => true) {\n const requiredCheckboxes = querySelectorAllNodes(this.selector, nodes)\n\n for (const checkbox of requiredCheckboxes) {\n if (isRequired(checkbox)) {\n const group = checkboxGroup(checkbox)\n\n if (this.willValidateGroup(group)) {\n for (const checkboxInGroup of group) {\n this.swapRequiredWithAriaRequired(checkboxInGroup)\n\n if (willReport(checkboxInGroup)) {\n this.validate(checkboxInGroup)\n }\n }\n }\n }\n }\n }\n\n swapRequiredWithAriaRequired(element) {\n this.ignoringMutations = true\n element.required = false\n element.setAttribute(\"aria-required\", \"true\")\n setTimeout(() => this.ignoringMutations = false, 0)\n }\n\n willValidateGroup(group) {\n return group.length > 0 && this.enabled(group)\n }\n\n get element() {\n return this.constraintValidations.element\n }\n}\n\nfunction checkboxGroup(formControl) {\n const results = new Set\n const { name, form } = formControl\n\n if (name && form instanceof HTMLFormElement) {\n const group = form.elements.namedItem(name)\n const elements = Symbol.iterator in group ?\n group :\n [group]\n\n for (const element of elements) {\n if (element.type === \"checkbox\") {\n results.add(element)\n }\n }\n\n if (results.size === 1 && results.has(formControl)) {\n results.clear()\n }\n }\n\n return Array.from(results)\n}\n\nfunction querySelectorAllNodes(selector, nodes, elements = new Set) {\n for (const node of nodes) {\n if (node instanceof Element) {\n if (node.matches(selector)) {\n elements.add(node)\n }\n\n const childNodes = querySelectorAllNodes(selector, node.children, elements)\n\n for (const childNode of childNodes) {\n elements.add(childNode)\n }\n }\n }\n\n return Array.from(elements)\n}\n\nfunction isCheckboxElement(element) {\n return isFieldElement(element) && element.type === \"checkbox\"\n}\n\nfunction isRequired(element) {\n return element.required || element.getAttribute(\"aria-required\") === \"true\"\n}\n","import { isAriaInvalid, isFieldElement, readValidationMessages } from \"./util\"\nimport CheckboxValidator from \"./validators/checkbox_validator\"\n\nconst defaultOptions = {\n disableSubmitWhenInvalid: false,\n validateOn: [\"blur\", \"input\"],\n validators: {\n checkbox: false\n }\n}\n\nexport default class ConstraintValidations {\n static connect(element = document, options = {}) {\n new this(element, options).connect()\n }\n\n constructor(element = document, options = {}) {\n this.element = element\n this.options = { ...defaultOptions, ...options }\n this.validators = [\n new CheckboxValidator(this, this.options.validators.checkbox)\n ]\n }\n\n connect() {\n this.validators.forEach(validator => validator.connect())\n this.element.addEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.addEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.addEventListener(\"input\", this.toggleSubmitsDisabled)\n\n this.reportValidationMessages(\n this.element instanceof HTMLFormElement ?\n [this.element] :\n this.element.querySelectorAll(\"form\")\n )\n }\n\n disconnect() {\n this.element.removeEventListener(\"invalid\", this.reportFieldValidity, { capture: true, passive: false })\n\n for (const eventName of this.options.validateOn) {\n this.element.removeEventListener(eventName, this.clearAndReportFieldValidity, { capture: true, passive: true })\n }\n\n this.element.removeEventListener(\"input\", this.toggleSubmitsDisabled)\n this.validators.forEach(validator => validator.disconnect())\n }\n\n reportFieldValidity = (event) => {\n if (isFieldElement(event.target) && this.reportValidity(event.target)) {\n event.preventDefault()\n\n focusFirstInvalidField(event.target.form || event.target)\n }\n }\n\n clearAndReportFieldValidity = ({ target }) => {\n if (isFieldElement(target)) {\n this.clearValidity(target)\n\n for (const validator of this.validators) {\n if (validator.willValidate(target)) {\n validator.validate(target)\n }\n }\n\n this.reportValidity(target)\n }\n }\n\n toggleSubmitsDisabled = ({ target }) => {\n if (isFieldElement(target) && this.willDisableSubmitWhenInvalid(target)) {\n disableSubmitWhenInvalid(target.form)\n }\n }\n\n reportValidationMessages(forms) {\n const invalidFields = []\n\n for (const form of forms) {\n for (const element of Array.from(form.elements).filter(isFieldElement)) {\n const serverRenderedInvalid = isAriaInvalid(element)\n const id = element.getAttribute(\"aria-errormessage\")\n const errorMessageElement = document.getElementById(id)\n const validationMessage = errorMessageElement?.textContent\n\n if (validationMessage) {\n element.setCustomValidity(validationMessage)\n }\n\n if (validationMessage || serverRenderedInvalid) {\n this.reportValidity(element)\n invalidFields.push(element)\n }\n\n if (this.willDisableSubmitWhenInvalid(element)) {\n disableSubmitWhenInvalid(form)\n }\n }\n }\n\n const [firstInvalidField] = invalidFields\n firstInvalidField?.focus()\n }\n\n willDisableSubmitWhenInvalid(target) {\n return typeof this.options.disableSubmitWhenInvalid === \"function\" ?\n this.options.disableSubmitWhenInvalid(target) :\n !!this.options.disableSubmitWhenInvalid\n }\n\n clearValidity(input) {\n input.setCustomValidity(\"\")\n\n this.reportValidity(input)\n }\n\n reportValidity(input) {\n const id = input.getAttribute(\"aria-errormessage\")\n const validationMessage = getValidationMessage(input)\n const element = document.getElementById(id) || createValidationMessageFragment(input.form)\n\n if (input.form?.noValidate) {\n return false\n } else if (id && element) {\n element.id = id\n element.innerHTML = validationMessage\n\n if (validationMessage) {\n input.setCustomValidity(validationMessage)\n input.setAttribute(\"aria-describedby\", id)\n input.setAttribute(\"aria-invalid\", \"true\")\n } else {\n input.removeAttribute(\"aria-describedby\")\n input.removeAttribute(\"aria-invalid\")\n }\n\n if (!element.parentElement) {\n input.insertAdjacentElement(\"afterend\", element)\n }\n\n if (input.form && this.willDisableSubmitWhenInvalid(input)) disableSubmitWhenInvalid(input.form)\n\n return true\n } else {\n return false\n }\n }\n}\n\nfunction focusFirstInvalidField(element) {\n if (element instanceof HTMLFormElement) {\n return Array.from(element.elements).some(field => focusFirstInvalidField(field))\n } else if (isFieldElement(element) && !element.validity.valid) {\n element.focus()\n element.scrollIntoView()\n return true\n } else {\n return false\n }\n}\n\nfunction disableSubmitWhenInvalid(form) {\n if (!form || form.noValidate) return\n\n const isValid = Array.from(form.elements).filter(isFieldElement).every(input => input.validity.valid)\n\n for (const element of form.elements) {\n if (element.type == \"submit\" && !element.formNoValidate) {\n element.disabled = !isValid\n }\n }\n}\n\nfunction createValidationMessageFragment(form) {\n if (form) {\n const template = form.querySelector(\"[data-validation-message-template]\")\n\n return template?.content.children[0].cloneNode()\n }\n}\n\nfunction getValidationMessage(input) {\n const validationMessages = Object.entries(readValidationMessages(input))\n\n const [ _, validationMessage ] = validationMessages.find(([ key ]) => input.validity[key]) || [ null, null ]\n\n return validationMessage || input.validationMessage\n}\n"],"names":["isFieldElement","element","disabled","willValidate","isAriaInvalid","getAttribute","readValidationMessages","input","JSON","parse","_","[object Object]","constraintValidations","predicate","this","mutationObserver","MutationObserver","handleMutation","enabled","group","addEventListener","handleInvalid","capture","passive","observe","attributeFilter","childList","subtree","reportValidationMessages","querySelectorAll","selector","removeEventListener","disconnect","target","willValidateGroup","checkboxGroup","checkboxesInGroup","filter","isCheckboxElement","allRequired","every","checkbox","isRequired","someChecked","some","checked","clearValidity","validationMessages","setCustomValidity","valueMissing","reportValidity","checkboxes","Set","form","elements","add","mutationRecords","ignoringMutations","addedNodes","type","required","swapRequiredWithAriaRequired","removeAttribute","length","nodes","willReport","requiredCheckboxes","querySelectorAllNodes","checkboxInGroup","validate","setAttribute","setTimeout","formControl","results","name","HTMLFormElement","namedItem","Symbol","iterator","size","has","clear","Array","from","node","Element","matches","childNodes","children","childNode","defaultOptions","disableSubmitWhenInvalid","validateOn","validators","ConstraintValidations","document","options","connect","CheckboxValidator","forEach","validator","reportFieldValidity","eventName","clearAndReportFieldValidity","toggleSubmitsDisabled","event","preventDefault","focusFirstInvalidField","willDisableSubmitWhenInvalid","forms","invalidFields","serverRenderedInvalid","id","errorMessageElement","getElementById","validationMessage","textContent","push","firstInvalidField","focus","getValidationMessage","createValidationMessageFragment","noValidate","innerHTML","parentElement","insertAdjacentElement","field","validity","valid","scrollIntoView","isValid","formNoValidate","template","querySelector","content","cloneNode","Object","entries","find","key"],"mappings":";;EAAO,SAASA,eAAeC;IAC7B,QAAQA,QAAQC,YAAY,cAAcD,WAAWA,QAAQE;;EAGxD,SAASC,cAAcH;IAC5B,OAAOA,QAAQI,aAAa,oBAAoB;;EAG3C,SAASC,uBAAuBC;IACrC;MACE,OAAOC,KAAKC,MAAMF,MAAMF,aAAa,gCAAgC;MACrE,OAAMK;MACN,OAAO;;;ECVI;IACbC,SAAW;IACXA,kBAAoB;IAEpBA,YAAYC,uBAAuBC;MACjCC,KAAKF,wBAAwBA;MAC7BE,KAAKC,mBAAmB,IAAIC,iBAAiBF,KAAKG;MAClDH,KAAKI,iBAAiBL,cAAc,aAClCA,YACCM,WAAYN;;IAGjBF;MACEG,KAAKb,QAAQmB,iBAAiB,WAAWN,KAAKO,eAAe;QAAEC,SAAS;QAAMC,SAAS;;MACvFT,KAAKC,iBAAiBS,QAAQV,KAAKb,SAAS;QAC1CwB,iBAAiB,EAAC;QAClBC,WAAW;QACXC,SAAS;;MAEXb,KAAKc,yBAAyBd,KAAKb,QAAQ4B,iBAAiBf,KAAKgB,WAAW1B;;IAG9EO;MACEG,KAAKb,QAAQ8B,oBAAoB,WAAWjB,KAAKO,eAAe;QAAEC,SAAS;QAAMC,SAAS;;MAC1FT,KAAKC,iBAAiBiB;;IAGxBrB,aAAasB;MACX,OAAOnB,KAAKoB,kBAAkBC,cAAcF;;IAG9CtB,SAASsB;MACP,MAAMG,oBAAoBD,cAAcF,QAAQI,OAAOC;MACvD,MAAMC,cAAcH,kBAAkBI,OAAOC,YAAaC,WAAWD;MACrE,MAAME,cAAcP,kBAAkBQ,MAAMH,YAAaA,SAASI;MAElE,IAAIN,eAAeI,aAAa;QAC9B,KAAK,MAAMF,YAAYL,mBAAmB;UACxCtB,KAAKF,sBAAsBkC,cAAcL;;aAEtC,IAAIF,aAAa;QACtB,KAAK,MAAME,YAAYL,mBAAmB;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AAMuD,gBAAgB;UACtBvD,MAAMuD,gBAAgB;;QAGxB,KAAK7D,QAAQ2H,eAAe;UAC1BrH,MAAMsH,sBAAsB,YAAY5H;;QAG1C,IAAIM,MAAM8C,QAAQvC,KAAK8F,6BAA6BrG,QAAQoF,yBAAyBpF,MAAM8C;QAE3F,OAAO;aACF;QACL,OAAO;;;;EAKb,SAASsD,uBAAuB1G;IAC9B,IAAIA,mBAAmB0E,iBAAiB;MACtC,OAAOO,MAAMC,KAAKlF,QAAQqD,UAAUV,MAAKkF,SAASnB,uBAAuBmB;WACpE,IAAI9H,eAAeC,aAAaA,QAAQ8H,SAASC,OAAO;MAC7D/H,QAAQsH;MACRtH,QAAQgI;MACR,OAAO;WACF;MACL,OAAO;;;EAIX,SAAStC,yBAAyBtC;IAChC,KAAKA,QAAQA,KAAKqE,YAAY;IAE9B,MAAMQ,UAAUhD,MAAMC,KAAK9B,KAAKC,UAAUjB,OAAOrC,gBAAgBwC,OAAMjC,SAASA,MAAMwH,SAASC;IAE/F,KAAK,MAAM/H,WAAWoD,KAAKC,UAAU;MACnC,IAAIrD,QAAQ0D,QAAQ,aAAa1D,QAAQkI,gBAAgB;QACvDlI,QAAQC,YAAYgI;;;;EAK1B,SAAST,gCAAgCpE;IACvC,IAAIA,MAAM;MACR,MAAM+E,WAAW/E,KAAKgF,cAAc;MAEpC,OAAOD,UAAUE,QAAQ9C,SAAS,GAAG+C;;;EAIzC,SAASf,qBAAqBjH;IAC5B,MAAMwC,qBAAqByF,OAAOC,QAAQnI,uBAAuBC;IAEjE,OAAQG,GAAGyG,qBAAsBpE,mBAAmB2F,MAAK,EAAGC,SAAUpI,MAAMwH,SAASY,UAAS,EAAE,MAAM;IAEtG,OAAOxB,qBAAqB5G,MAAM4G;;;"} \ No newline at end of file diff --git a/app/javascript/constraint_validations/validators/checkbox_validator.js b/app/javascript/constraint_validations/validators/checkbox_validator.js index 5b3a17c..9139a6d 100644 --- a/app/javascript/constraint_validations/validators/checkbox_validator.js +++ b/app/javascript/constraint_validations/validators/checkbox_validator.js @@ -147,7 +147,11 @@ function querySelectorAllNodes(selector, nodes, elements = new Set) { elements.add(node) } - elements.add(...querySelectorAllNodes(selector, node.children, elements)) + const childNodes = querySelectorAllNodes(selector, node.children, elements) + + for (const childNode of childNodes) { + elements.add(childNode) + } } }