@ministryofjustice/frontend 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/moj/all.bundle.js +1549 -1062
- package/moj/all.bundle.js.map +1 -1
- package/moj/all.bundle.mjs +1845 -1054
- package/moj/all.bundle.mjs.map +1 -1
- package/moj/all.mjs +7 -90
- package/moj/all.mjs.map +1 -1
- package/moj/all.scss +1 -0
- package/moj/all.scss.map +1 -1
- package/moj/common/index.mjs +57 -0
- package/moj/common/index.mjs.map +1 -0
- package/moj/common/moj-frontend-version.mjs +14 -0
- package/moj/common/moj-frontend-version.mjs.map +1 -0
- package/moj/components/add-another/add-another.bundle.js +105 -76
- package/moj/components/add-another/add-another.bundle.js.map +1 -1
- package/moj/components/add-another/add-another.bundle.mjs +222 -71
- package/moj/components/add-another/add-another.bundle.mjs.map +1 -1
- package/moj/components/add-another/add-another.mjs +103 -72
- package/moj/components/add-another/add-another.mjs.map +1 -1
- package/moj/components/alert/alert.bundle.js +115 -191
- package/moj/components/alert/alert.bundle.js.map +1 -1
- package/moj/components/alert/alert.bundle.mjs +354 -186
- package/moj/components/alert/alert.bundle.mjs.map +1 -1
- package/moj/components/alert/alert.mjs +55 -140
- package/moj/components/alert/alert.mjs.map +1 -1
- package/moj/components/button-menu/README.md +3 -1
- package/moj/components/button-menu/button-menu.bundle.js +91 -120
- package/moj/components/button-menu/button-menu.bundle.js.map +1 -1
- package/moj/components/button-menu/button-menu.bundle.mjs +329 -114
- package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -1
- package/moj/components/button-menu/button-menu.mjs +89 -116
- package/moj/components/button-menu/button-menu.mjs.map +1 -1
- package/moj/components/date-picker/date-picker.bundle.js +174 -154
- package/moj/components/date-picker/date-picker.bundle.js.map +1 -1
- package/moj/components/date-picker/date-picker.bundle.mjs +411 -147
- package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -1
- package/moj/components/date-picker/date-picker.mjs +172 -150
- package/moj/components/date-picker/date-picker.mjs.map +1 -1
- package/moj/components/filter/template.njk +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +133 -44
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +374 -41
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +131 -40
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.js +159 -69
- package/moj/components/form-validator/form-validator.bundle.js.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.mjs +399 -65
- package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.mjs +134 -54
- package/moj/components/form-validator/form-validator.mjs.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js +291 -117
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +527 -109
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -1
- package/moj/components/multi-file-upload/multi-file-upload.mjs +288 -101
- package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
- package/moj/components/multi-file-upload/template.njk +1 -1
- package/moj/components/multi-select/multi-select.bundle.js +106 -41
- package/moj/components/multi-select/multi-select.bundle.js.map +1 -1
- package/moj/components/multi-select/multi-select.bundle.mjs +346 -37
- package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -1
- package/moj/components/multi-select/multi-select.mjs +104 -37
- package/moj/components/multi-select/multi-select.mjs.map +1 -1
- package/moj/components/password-reveal/_password-reveal.scss +3 -1
- package/moj/components/password-reveal/_password-reveal.scss.map +1 -1
- package/moj/components/password-reveal/password-reveal.bundle.js +32 -29
- package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -1
- package/moj/components/password-reveal/password-reveal.bundle.mjs +149 -24
- package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -1
- package/moj/components/password-reveal/password-reveal.mjs +30 -25
- package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
- package/moj/components/rich-text-editor/README.md +4 -3
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js +127 -62
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -1
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +367 -58
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -1
- package/moj/components/rich-text-editor/rich-text-editor.mjs +125 -58
- package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
- package/moj/components/search-toggle/search-toggle.bundle.js +94 -26
- package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -1
- package/moj/components/search-toggle/search-toggle.bundle.mjs +334 -22
- package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -1
- package/moj/components/search-toggle/search-toggle.mjs +92 -22
- package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
- package/moj/components/sortable-table/sortable-table.bundle.js +151 -83
- package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -1
- package/moj/components/sortable-table/sortable-table.bundle.mjs +390 -78
- package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -1
- package/moj/components/sortable-table/sortable-table.mjs +149 -79
- package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
- package/moj/core/_all.scss +3 -0
- package/moj/core/_all.scss.map +1 -0
- package/moj/core/_moj-frontend-properties.scss +7 -0
- package/moj/core/_moj-frontend-properties.scss.map +1 -0
- package/moj/filters/prototype-kit-13-filters.js +4 -3
- package/moj/helpers.bundle.js +22 -77
- package/moj/helpers.bundle.js.map +1 -1
- package/moj/helpers.bundle.mjs +23 -74
- package/moj/helpers.bundle.mjs.map +1 -1
- package/moj/helpers.mjs +23 -74
- package/moj/helpers.mjs.map +1 -1
- package/moj/moj-frontend.min.css +1 -1
- package/moj/moj-frontend.min.css.map +1 -1
- package/moj/moj-frontend.min.js +1 -1
- package/moj/moj-frontend.min.js.map +1 -1
- package/package.json +1 -1
- package/moj/version.bundle.js +0 -12
- package/moj/version.bundle.js.map +0 -1
- package/moj/version.bundle.mjs +0 -4
- package/moj/version.bundle.mjs.map +0 -1
- package/moj/version.mjs +0 -4
- package/moj/version.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-validator.bundle.mjs","sources":["../../../../src/moj/helpers.mjs","../../../../src/moj/components/form-validator/form-validator.mjs"],"sourcesContent":["export function removeAttributeValue(el, attr, value) {\n let re, m\n if (el.getAttribute(attr)) {\n if (el.getAttribute(attr) === value) {\n el.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = el.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n el.setAttribute(\n attr,\n el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\nexport function addAttributeValue(el, attr, value) {\n let re\n if (!el.getAttribute(attr)) {\n el.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test(el.getAttribute(attr))) {\n el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`)\n }\n }\n}\n\nexport function dragAndDropSupported() {\n const div = document.createElement('div')\n return typeof div.ondrop !== 'undefined'\n}\n\nexport function formDataSupported() {\n return typeof FormData === 'function'\n}\n\nexport function fileApiSupported() {\n const input = document.createElement('input')\n input.type = 'file'\n return typeof input.files !== 'undefined'\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @param {HTMLElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n if (options.onBlur) {\n options.onBlur.call($element)\n }\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n if (options.onBeforeFocus) {\n options.onBeforeFocus.call($element)\n }\n $element.focus()\n}\n","import { addAttributeValue, removeAttributeValue } from '../../helpers.mjs'\n\nexport class FormValidator {\n /**\n * @param {Element | null} form - HTML element to use for form validator\n * @param {FormValidatorConfig} [config] - Button menu config\n */\n constructor(form, config = {}) {\n if (!form || !(form instanceof HTMLFormElement)) {\n return this\n }\n\n this.form = form\n this.errors = []\n this.validators = []\n this.form.addEventListener('submit', this.onSubmit.bind(this))\n this.summary =\n config.summary || document.querySelector('.govuk-error-summary')\n this.originalTitle = document.title\n }\n\n escapeHtml(string) {\n return String(string).replace(/[&<>\"'`=/]/g, function fromEntityMap(s) {\n return FormValidator.entityMap[s]\n })\n }\n\n resetTitle() {\n document.title = this.originalTitle\n }\n\n updateTitle() {\n document.title = `${this.errors.length} errors - ${document.title}`\n }\n\n showSummary() {\n this.summary.innerHTML = this.getSummaryHtml()\n this.summary.classList.remove('moj-hidden')\n this.summary.setAttribute('aria-labelledby', 'errorSummary-heading')\n this.summary.focus()\n }\n\n getSummaryHtml() {\n let html =\n '<h2 id=\"error-summary-title\" class=\"govuk-error-summary__title\">There is a problem</h2>'\n html += '<div class=\"govuk-error-summary__body\">'\n html += '<ul class=\"govuk-list govuk-error-summary__list\">'\n for (const error of this.errors) {\n html += '<li>'\n html += `<a href=\"#${this.escapeHtml(error.fieldName)}\">`\n html += this.escapeHtml(error.message)\n html += '</a>'\n html += '</li>'\n }\n html += '</ul>'\n html += '</div>'\n return html\n }\n\n hideSummary() {\n this.summary.classList.add('moj-hidden')\n this.summary.removeAttribute('aria-labelledby')\n }\n\n onSubmit(event) {\n this.removeInlineErrors()\n this.hideSummary()\n this.resetTitle()\n if (!this.validate()) {\n event.preventDefault()\n this.updateTitle()\n this.showSummary()\n this.showInlineErrors()\n }\n }\n\n showInlineErrors() {\n for (const error of this.errors) {\n this.showInlineError(error)\n }\n }\n\n showInlineError(error) {\n const errorSpan = document.createElement('span')\n errorSpan.id = `${error.fieldName}-error`\n errorSpan.classList.add('govuk-error-message')\n errorSpan.innerHTML = this.escapeHtml(error.message)\n\n const control = document.querySelector(`#${error.fieldName}`)\n const fieldset = control.closest('.govuk-fieldset')\n const fieldContainer = (fieldset || control).closest('.govuk-form-group')\n\n const label = fieldContainer.querySelector('label')\n const legend = fieldContainer.querySelector('legend')\n\n fieldContainer.classList.add('govuk-form-group--error')\n\n if (fieldset && legend) {\n legend.after(errorSpan)\n fieldContainer.setAttribute('aria-invalid', 'true')\n addAttributeValue(fieldset, 'aria-describedby', errorSpan.id)\n } else if (label && control) {\n label.after(errorSpan)\n control.setAttribute('aria-invalid', 'true')\n addAttributeValue(control, 'aria-describedby', errorSpan.id)\n }\n }\n\n removeInlineErrors() {\n for (const error of this.errors) {\n this.removeInlineError(error)\n }\n }\n\n removeInlineError(error) {\n const errorSpan = document.querySelector(`#${error.fieldName}-error`)\n\n const control = document.querySelector(`#${error.fieldName}`)\n const fieldset = control.closest('.govuk-fieldset')\n const fieldContainer = (fieldset || control).closest('.govuk-form-group')\n\n const label = fieldContainer.querySelector('label')\n const legend = fieldContainer.querySelector('legend')\n\n errorSpan.remove()\n fieldContainer.classList.remove('govuk-form-group--error')\n\n if (fieldset && legend) {\n fieldContainer.removeAttribute('aria-invalid')\n removeAttributeValue(fieldset, 'aria-describedby', errorSpan.id)\n } else if (label && control) {\n control.removeAttribute('aria-invalid')\n removeAttributeValue(control, 'aria-describedby', errorSpan.id)\n }\n }\n\n addValidator(fieldName, rules) {\n this.validators.push({\n fieldName,\n rules,\n field: this.form.elements[fieldName]\n })\n }\n\n validate() {\n this.errors = []\n let validator = null\n let validatorReturnValue = true\n let i\n let j\n for (i = 0; i < this.validators.length; i++) {\n validator = this.validators[i]\n for (j = 0; j < validator.rules.length; j++) {\n validatorReturnValue = validator.rules[j].method(\n validator.field,\n validator.rules[j].params\n )\n\n if (\n typeof validatorReturnValue === 'boolean' &&\n !validatorReturnValue\n ) {\n this.errors.push({\n fieldName: validator.fieldName,\n message: validator.rules[j].message\n })\n break\n } else if (typeof validatorReturnValue === 'string') {\n this.errors.push({\n fieldName: validatorReturnValue,\n message: validator.rules[j].message\n })\n break\n }\n }\n }\n return this.errors.length === 0\n }\n\n static entityMap = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '/': '/',\n '`': '`',\n '=': '='\n }\n}\n\n/**\n * @typedef {object} FormValidatorConfig\n * @property {HTMLElement} [summary] - HTML element to use for error summary\n */\n"],"names":["removeAttributeValue","el","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","FormValidator","constructor","form","config","HTMLFormElement","errors","validators","addEventListener","onSubmit","bind","summary","document","querySelector","originalTitle","title","escapeHtml","string","String","fromEntityMap","s","entityMap","resetTitle","updateTitle","showSummary","innerHTML","getSummaryHtml","classList","remove","focus","html","error","fieldName","message","hideSummary","add","event","removeInlineErrors","validate","preventDefault","showInlineErrors","showInlineError","errorSpan","createElement","id","control","fieldset","closest","fieldContainer","label","legend","after","removeInlineError","addValidator","rules","push","field","elements","validator","validatorReturnValue","i","j","method","params"],"mappings":"AAAO,SAASA,oBAAoBA,CAACC,EAAE,EAAEC,IAAI,EAAEC,KAAK,EAAE;EACpD,IAAIC,EAAE,EAAEC,CAAC;AACT,EAAA,IAAIJ,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;IACzB,IAAID,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;AACnCF,MAAAA,EAAE,CAACM,eAAe,CAACL,IAAI,CAAC;AAC1B,KAAC,MAAM;AACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAA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OAAO,EAAEyB,SAAS,CAACJ,KAAK,CAACO,CAAC,CAAC,CAAC5B;AAC9B,WAAC,CAAC;AACF,UAAA;AACF;AACF;AACF;AACA,IAAA,OAAO,IAAI,CAAC3B,MAAM,CAACV,MAAM,KAAK,CAAC;AACjC;AAYF;;AAEA;AACA;AACA;AACA;AAhMaK,aAAa,CAiLjBoB,SAAS,GAAG;AACjB,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE;AACP,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"form-validator.bundle.mjs","sources":["../../../../node_modules/govuk-frontend/dist/govuk/common/index.mjs","../../../../node_modules/govuk-frontend/dist/govuk/errors/index.mjs","../../../../node_modules/govuk-frontend/dist/govuk/component.mjs","../../../../node_modules/govuk-frontend/dist/govuk/common/configuration.mjs","../../../../src/moj/helpers.mjs","../../../../src/moj/components/form-validator/form-validator.mjs"],"sourcesContent":["function getFragmentFromUrl(url) {\n if (!url.includes('#')) {\n return undefined;\n }\n return url.split('#').pop();\n}\nfunction getBreakpoint(name) {\n const property = `--govuk-frontend-breakpoint-${name}`;\n const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);\n return {\n property,\n value: value || undefined\n };\n}\nfunction setFocus($element, options = {}) {\n var _options$onBeforeFocu;\n const isFocusable = $element.getAttribute('tabindex');\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1');\n }\n function onFocus() {\n $element.addEventListener('blur', onBlur, {\n once: true\n });\n }\n function onBlur() {\n var _options$onBlur;\n (_options$onBlur = options.onBlur) == null || _options$onBlur.call($element);\n if (!isFocusable) {\n $element.removeAttribute('tabindex');\n }\n }\n $element.addEventListener('focus', onFocus, {\n once: true\n });\n (_options$onBeforeFocu = options.onBeforeFocus) == null || _options$onBeforeFocu.call($element);\n $element.focus();\n}\nfunction isInitialised($root, moduleName) {\n return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nfunction isSupported($scope = document.body) {\n if (!$scope) {\n return false;\n }\n return $scope.classList.contains('govuk-frontend-supported');\n}\nfunction isArray(option) {\n return Array.isArray(option);\n}\nfunction isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option);\n}\nfunction formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`;\n}\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n/**\n * @import { ObjectNested } from './configuration.mjs'\n */\n\nexport { formatErrorMessage, getBreakpoint, getFragmentFromUrl, isInitialised, isObject, isSupported, setFocus };\n//# sourceMappingURL=index.mjs.map\n","import { formatErrorMessage } from '../common/index.mjs';\n\nclass GOVUKFrontendError extends Error {\n constructor(...args) {\n super(...args);\n this.name = 'GOVUKFrontendError';\n }\n}\nclass SupportError extends GOVUKFrontendError {\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support\n */\n constructor($scope = document.body) {\n const supportMessage = 'noModule' in HTMLScriptElement.prototype ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet' : 'GOV.UK Frontend is not supported in this browser';\n super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type=\"module\">`');\n this.name = 'SupportError';\n }\n}\nclass ConfigError extends GOVUKFrontendError {\n constructor(...args) {\n super(...args);\n this.name = 'ConfigError';\n }\n}\nclass ElementError extends GOVUKFrontendError {\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';\n if (typeof messageOrOptions === 'object') {\n const {\n component,\n identifier,\n element,\n expectedType\n } = messageOrOptions;\n message = identifier;\n message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';\n message = formatErrorMessage(component, message);\n }\n super(message);\n this.name = 'ElementError';\n }\n}\nclass InitError extends GOVUKFrontendError {\n constructor(componentOrMessage) {\n const message = typeof componentOrMessage === 'string' ? componentOrMessage : formatErrorMessage(componentOrMessage, `Root element (\\`$root\\`) already initialised`);\n super(message);\n this.name = 'InitError';\n }\n}\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n\nexport { ConfigError, ElementError, GOVUKFrontendError, InitError, SupportError };\n//# sourceMappingURL=index.mjs.map\n","import { isInitialised, isSupported } from './common/index.mjs';\nimport { InitError, ElementError, SupportError } from './errors/index.mjs';\n\nclass Component {\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root;\n }\n constructor($root) {\n this._$root = void 0;\n const childConstructor = this.constructor;\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`);\n }\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n });\n } else {\n this._$root = $root;\n }\n childConstructor.checkSupport();\n this.checkInitialised();\n const moduleName = childConstructor.moduleName;\n this.$root.setAttribute(`data-${moduleName}-init`, '');\n }\n checkInitialised() {\n const constructor = this.constructor;\n const moduleName = constructor.moduleName;\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor);\n }\n }\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError();\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\nComponent.elementType = HTMLElement;\n\nexport { Component };\n//# sourceMappingURL=component.mjs.map\n","import { Component } from '../component.mjs';\nimport { ConfigError } from '../errors/index.mjs';\nimport { isObject, formatErrorMessage } from './index.mjs';\n\nconst configOverride = Symbol.for('configOverride');\nclass ConfigurableComponent extends Component {\n [configOverride](param) {\n return {};\n }\n\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {ConfigurationType} - the root element of component\n */\n get config() {\n return this._config;\n }\n constructor($root, config) {\n super($root);\n this._config = void 0;\n const childConstructor = this.constructor;\n if (!isObject(childConstructor.defaults)) {\n throw new ConfigError(formatErrorMessage(childConstructor, 'Config passed as parameter into constructor but no defaults defined'));\n }\n const datasetConfig = normaliseDataset(childConstructor, this._$root.dataset);\n this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {}, this[configOverride](datasetConfig), datasetConfig);\n }\n}\nfunction normaliseString(value, property) {\n const trimmedValue = value ? value.trim() : '';\n let output;\n let outputType = property == null ? void 0 : property.type;\n if (!outputType) {\n if (['true', 'false'].includes(trimmedValue)) {\n outputType = 'boolean';\n }\n if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {\n outputType = 'number';\n }\n }\n switch (outputType) {\n case 'boolean':\n output = trimmedValue === 'true';\n break;\n case 'number':\n output = Number(trimmedValue);\n break;\n default:\n output = value;\n }\n return output;\n}\nfunction normaliseDataset(Component, dataset) {\n if (!isObject(Component.schema)) {\n throw new ConfigError(formatErrorMessage(Component, 'Config passed as parameter into constructor but no schema defined'));\n }\n const out = {};\n const entries = Object.entries(Component.schema.properties);\n for (const entry of entries) {\n const [namespace, property] = entry;\n const field = namespace.toString();\n if (field in dataset) {\n out[field] = normaliseString(dataset[field], property);\n }\n if ((property == null ? void 0 : property.type) === 'object') {\n out[field] = extractConfigByNamespace(Component.schema, dataset, namespace);\n }\n }\n return out;\n}\nfunction mergeConfigs(...configObjects) {\n const formattedConfigObject = {};\n for (const configObject of configObjects) {\n for (const key of Object.keys(configObject)) {\n const option = formattedConfigObject[key];\n const override = configObject[key];\n if (isObject(option) && isObject(override)) {\n formattedConfigObject[key] = mergeConfigs(option, override);\n } else {\n formattedConfigObject[key] = override;\n }\n }\n }\n return formattedConfigObject;\n}\nfunction validateConfig(schema, config) {\n const validationErrors = [];\n for (const [name, conditions] of Object.entries(schema)) {\n const errors = [];\n if (Array.isArray(conditions)) {\n for (const {\n required,\n errorMessage\n } of conditions) {\n if (!required.every(key => !!config[key])) {\n errors.push(errorMessage);\n }\n }\n if (name === 'anyOf' && !(conditions.length - errors.length >= 1)) {\n validationErrors.push(...errors);\n }\n }\n }\n return validationErrors;\n}\nfunction extractConfigByNamespace(schema, dataset, namespace) {\n const property = schema.properties[namespace];\n if ((property == null ? void 0 : property.type) !== 'object') {\n return;\n }\n const newObject = {\n [namespace]: {}\n };\n for (const [key, value] of Object.entries(dataset)) {\n let current = newObject;\n const keyParts = key.split('.');\n for (const [index, name] of keyParts.entries()) {\n if (isObject(current)) {\n if (index < keyParts.length - 1) {\n if (!isObject(current[name])) {\n current[name] = {};\n }\n current = current[name];\n } else if (key !== namespace) {\n current[name] = normaliseString(value);\n }\n }\n }\n }\n return newObject[namespace];\n}\n/**\n * Schema for component config\n *\n * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType\n * @typedef {object} Schema\n * @property {Record<keyof ConfigurationType, SchemaProperty | undefined>} properties - Schema properties\n * @property {SchemaCondition<ConfigurationType>[]} [anyOf] - List of schema conditions\n */\n/**\n * Schema property for component config\n *\n * @typedef {object} SchemaProperty\n * @property {'string' | 'boolean' | 'number' | 'object'} type - Property type\n */\n/**\n * Schema condition for component config\n *\n * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType\n * @typedef {object} SchemaCondition\n * @property {(keyof ConfigurationType)[]} required - List of required config fields\n * @property {string} errorMessage - Error message when required config fields not provided\n */\n/**\n * @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n * @property {Schema<ConfigurationType>} [schema] - The schema of the component configuration\n * @property {ConfigurationType} [defaults] - The default values of the configuration of the component\n */\n/**\n * @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]\n * @typedef {typeof Component & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>\n */\n\nexport { ConfigurableComponent, configOverride, extractConfigByNamespace, mergeConfigs, normaliseDataset, normaliseString, validateConfig };\n//# sourceMappingURL=configuration.mjs.map\n","/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n","import { ConfigurableComponent } from 'govuk-frontend'\n\nimport { addAttributeValue, removeAttributeValue } from '../../helpers.mjs'\n\n/**\n * @augments {ConfigurableComponent<FormValidatorConfig, HTMLFormElement>}\n */\nexport class FormValidator extends ConfigurableComponent {\n /**\n * @param {Element | null} $root - HTML element to use for form validator\n * @param {FormValidatorConfig} [config] - Form validator config\n */\n constructor($root, config = {}) {\n super($root, config)\n\n const $summary =\n this.config.summary.element ||\n document.querySelector(this.config.summary.selector)\n\n if (!$summary || !($summary instanceof HTMLElement)) {\n return this\n }\n\n this.$summary = $summary\n\n this.errors = /** @type {ValidationError[]} */ ([])\n this.validators = /** @type {Validator[]} */ ([])\n this.originalTitle = document.title\n\n this.$root.addEventListener('submit', this.onSubmit.bind(this))\n }\n\n escapeHtml(string = '') {\n return String(string).replace(\n /[&<>\"'`=/]/g,\n (name) => FormValidator.entityMap[name]\n )\n }\n\n resetTitle() {\n document.title = this.originalTitle\n }\n\n updateTitle() {\n document.title = `${this.errors.length} errors - ${document.title}`\n }\n\n showSummary() {\n this.$summary.innerHTML = this.getSummaryHtml()\n this.$summary.classList.remove('moj-hidden')\n this.$summary.setAttribute('aria-labelledby', 'errorSummary-heading')\n this.$summary.focus()\n }\n\n getSummaryHtml() {\n let html =\n '<h2 id=\"error-summary-title\" class=\"govuk-error-summary__title\">There is a problem</h2>'\n html += '<div class=\"govuk-error-summary__body\">'\n html += '<ul class=\"govuk-list govuk-error-summary__list\">'\n for (const error of this.errors) {\n html += '<li>'\n html += `<a href=\"#${this.escapeHtml(error.fieldName)}\">`\n html += this.escapeHtml(error.message)\n html += '</a>'\n html += '</li>'\n }\n html += '</ul>'\n html += '</div>'\n return html\n }\n\n hideSummary() {\n this.$summary.classList.add('moj-hidden')\n this.$summary.removeAttribute('aria-labelledby')\n }\n\n /**\n * @param {SubmitEvent} event - Form submit event\n */\n onSubmit(event) {\n this.removeInlineErrors()\n this.hideSummary()\n this.resetTitle()\n if (!this.validate()) {\n event.preventDefault()\n this.updateTitle()\n this.showSummary()\n this.showInlineErrors()\n }\n }\n\n showInlineErrors() {\n for (const error of this.errors) {\n this.showInlineError(error)\n }\n }\n\n /**\n * @param {ValidationError} error\n */\n showInlineError(error) {\n const $errorSpan = document.createElement('span')\n $errorSpan.id = `${error.fieldName}-error`\n $errorSpan.classList.add('govuk-error-message')\n $errorSpan.innerHTML = this.escapeHtml(error.message)\n\n const $control = document.querySelector(`#${error.fieldName}`)\n const $fieldset = $control.closest('.govuk-fieldset')\n const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group')\n\n const $label = $fieldContainer.querySelector('label')\n const $legend = $fieldContainer.querySelector('legend')\n\n $fieldContainer.classList.add('govuk-form-group--error')\n\n if ($fieldset && $legend) {\n $legend.after($errorSpan)\n $fieldContainer.setAttribute('aria-invalid', 'true')\n addAttributeValue($fieldset, 'aria-describedby', $errorSpan.id)\n } else if ($label && $control) {\n $label.after($errorSpan)\n $control.setAttribute('aria-invalid', 'true')\n addAttributeValue($control, 'aria-describedby', $errorSpan.id)\n }\n }\n\n removeInlineErrors() {\n for (const error of this.errors) {\n this.removeInlineError(error)\n }\n }\n\n /**\n * @param {ValidationError} error\n */\n removeInlineError(error) {\n const $errorSpan = document.querySelector(`#${error.fieldName}-error`)\n\n const $control = document.querySelector(`#${error.fieldName}`)\n const $fieldset = $control.closest('.govuk-fieldset')\n const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group')\n\n const $label = $fieldContainer.querySelector('label')\n const $legend = $fieldContainer.querySelector('legend')\n\n $errorSpan.remove()\n $fieldContainer.classList.remove('govuk-form-group--error')\n\n if ($fieldset && $legend) {\n $fieldContainer.removeAttribute('aria-invalid')\n removeAttributeValue($fieldset, 'aria-describedby', $errorSpan.id)\n } else if ($label && $control) {\n $control.removeAttribute('aria-invalid')\n removeAttributeValue($control, 'aria-describedby', $errorSpan.id)\n }\n }\n\n /**\n * @param {string} fieldName - Field name\n * @param {ValidationRule[]} rules - Validation rules\n */\n addValidator(fieldName, rules) {\n this.validators.push({\n fieldName,\n rules,\n field: this.$root.elements.namedItem(fieldName)\n })\n }\n\n validate() {\n this.errors = []\n\n /** @type {Validator | null} */\n let validator = null\n\n /** @type {boolean | string} */\n let validatorReturnValue = true\n\n let i\n let j\n\n for (i = 0; i < this.validators.length; i++) {\n validator = this.validators[i]\n for (j = 0; j < validator.rules.length; j++) {\n validatorReturnValue = validator.rules[j].method(\n validator.field,\n validator.rules[j].params\n )\n\n if (\n typeof validatorReturnValue === 'boolean' &&\n !validatorReturnValue\n ) {\n this.errors.push({\n fieldName: validator.fieldName,\n message: validator.rules[j].message\n })\n break\n } else if (typeof validatorReturnValue === 'string') {\n this.errors.push({\n fieldName: validatorReturnValue,\n message: validator.rules[j].message\n })\n break\n }\n }\n }\n return this.errors.length === 0\n }\n\n /**\n * @type {Record<string, string>}\n */\n static entityMap = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '/': '/',\n '`': '`',\n '=': '='\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-form-validator'\n\n /**\n * Multi file upload default config\n *\n * @type {FormValidatorConfig}\n */\n static defaults = Object.freeze({\n summary: {\n selector: '.govuk-error-summary'\n }\n })\n\n /**\n * Multi file upload config schema\n *\n * @satisfies {Schema<FormValidatorConfig>}\n */\n static schema = Object.freeze(\n /** @type {const} */ ({\n properties: {\n summary: { type: 'object' }\n }\n })\n )\n}\n\n/**\n * @typedef {object} FormValidatorConfig\n * @property {object} [summary] - Error summary config\n * @property {string} [summary.selector] - Selector for error summary\n * @property {Element | null} [summary.element] - HTML element for error summary\n */\n\n/**\n * @typedef {object} ValidationRule\n * @property {(field: Validator['field'], params: Record<string, Validator['field']>) => boolean | string} method - Validation method\n * @property {string} message - Error message\n * @property {Record<string, Validator['field']>} [params] - Parameters for validation\n */\n\n/**\n * @typedef {object} ValidationError\n * @property {string} fieldName - Name of the field\n * @property {string} message - Validation error message\n */\n\n/**\n * @typedef {object} Validator\n * @property {string} fieldName - Name of the field\n * @property {ValidationRule[]} rules - Validation rules\n * @property {Element | RadioNodeList} field - Form field\n */\n\n/**\n * @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'\n */\n"],"names":["isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","isArray","option","Array","isObject","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","supportMessage","HTMLScriptElement","prototype","ConfigError","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_$root","childConstructor","elementType","checkSupport","checkInitialised","setAttribute","configOverride","Symbol","for","ConfigurableComponent","param","config","_config","defaults","datasetConfig","normaliseDataset","dataset","mergeConfigs","normaliseString","value","property","trimmedValue","trim","output","outputType","type","includes","length","isFinite","Number","schema","out","entries","Object","properties","entry","namespace","field","toString","extractConfigByNamespace","configObjects","formattedConfigObject","configObject","key","keys","override","newObject","current","keyParts","split","index","removeAttributeValue","$element","attr","re","m","getAttribute","removeAttribute","RegExp","match","replace","addAttributeValue","test","FormValidator","$summary","summary","querySelector","selector","errors","validators","originalTitle","title","addEventListener","onSubmit","bind","escapeHtml","string","String","entityMap","resetTitle","updateTitle","showSummary","innerHTML","getSummaryHtml","remove","focus","html","error","fieldName","hideSummary","add","event","removeInlineErrors","validate","preventDefault","showInlineErrors","showInlineError","$errorSpan","createElement","id","$control","$fieldset","closest","$fieldContainer","$label","$legend","after","removeInlineError","addValidator","rules","push","elements","namedItem","validator","validatorReturnValue","i","j","method","params","freeze"],"mappings":"AAqGO,SAASA,aAAaA,CAACC,KAAK,EAAEC,UAAU,EAAE;EAC/C,OACED,KAAK,YAAYE,WAAW,IAC5BF,KAAK,CAACG,YAAY,CAAC,CAAA,KAAA,EAAQF,UAAU,CAAA,KAAA,CAAO,CAAC;AAEjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,WAAWA,CAACC,MAAM,GAAGC,QAAQ,CAACC,IAAI,EAAE;EAClD,IAAI,CAACF,MAAM,EAAE;AACX,IAAA,OAAO,KAAK;AACd;AAEA,EAAA,OAAOA,MAAM,CAACG,SAAS,CAACC,QAAQ,CAAC,0BAA0B,CAAC;AAC9D;AASA,SAASC,OAAOA,CAACC,MAAM,EAAE;AACvB,EAAA,OAAOC,KAAK,CAACF,OAAO,CAACC,MAAM,CAAC;AAC9B;AAUO,SAASE,QAAQA,CAACF,MAAM,EAAE;AAC/B,EAAA,OAAO,CAAC,CAACA,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM,CAAC;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;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AApRaoC,aAAa,CA8MjBe,SAAS,GAAG;AACjB,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE;AACP,CAAC;AAED;AACF;AACA;AA3Naf,aAAa,CA4NjBjG,UAAU,GAAG,oBAAoB;AAExC;AACF;AACA;AACA;AACA;AAlOaiG,aAAa,CAmOjBlD,QAAQ,GAAGoB,MAAM,CAACsF,MAAM,CAAC;AAC9BtD,EAAAA,OAAO,EAAE;AACPE,IAAAA,QAAQ,EAAE;AACZ;AACF,CAAC,CAAC;AAEF;AACF;AACA;AACA;AACA;AA7OaJ,aAAa,CA8OjBjC,MAAM,GAAGG,MAAM,CAACsF,MAAM,qBACL;AACpBrF,EAAAA,UAAU,EAAE;AACV+B,IAAAA,OAAO,EAAE;AAAExC,MAAAA,IAAI,EAAE;AAAS;AAC5B;AACF,CACF,CAAC;;;;","x_google_ignoreList":[0,1,2,3]}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
+
import { ConfigurableComponent } from 'govuk-frontend';
|
|
1
2
|
import { addAttributeValue, removeAttributeValue } from '../../helpers.mjs';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @augments {ConfigurableComponent<FormValidatorConfig, HTMLFormElement>}
|
|
6
|
+
*/
|
|
7
|
+
class FormValidator extends ConfigurableComponent {
|
|
4
8
|
/**
|
|
5
|
-
* @param {Element | null}
|
|
6
|
-
* @param {FormValidatorConfig} [config] -
|
|
9
|
+
* @param {Element | null} $root - HTML element to use for form validator
|
|
10
|
+
* @param {FormValidatorConfig} [config] - Form validator config
|
|
7
11
|
*/
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
12
|
+
constructor($root, config = {}) {
|
|
13
|
+
super($root, config);
|
|
14
|
+
const $summary = this.config.summary.element || document.querySelector(this.config.summary.selector);
|
|
15
|
+
if (!$summary || !($summary instanceof HTMLElement)) {
|
|
10
16
|
return this;
|
|
11
17
|
}
|
|
12
|
-
this
|
|
13
|
-
this.errors = [];
|
|
14
|
-
this.validators = [];
|
|
15
|
-
this.form.addEventListener('submit', this.onSubmit.bind(this));
|
|
16
|
-
this.summary = config.summary || document.querySelector('.govuk-error-summary');
|
|
18
|
+
this.$summary = $summary;
|
|
19
|
+
this.errors = /** @type {ValidationError[]} */[];
|
|
20
|
+
this.validators = /** @type {Validator[]} */[];
|
|
17
21
|
this.originalTitle = document.title;
|
|
22
|
+
this.$root.addEventListener('submit', this.onSubmit.bind(this));
|
|
18
23
|
}
|
|
19
|
-
escapeHtml(string) {
|
|
20
|
-
return String(string).replace(/[&<>"'`=/]/g,
|
|
21
|
-
return FormValidator.entityMap[s];
|
|
22
|
-
});
|
|
24
|
+
escapeHtml(string = '') {
|
|
25
|
+
return String(string).replace(/[&<>"'`=/]/g, name => FormValidator.entityMap[name]);
|
|
23
26
|
}
|
|
24
27
|
resetTitle() {
|
|
25
28
|
document.title = this.originalTitle;
|
|
@@ -28,10 +31,10 @@ class FormValidator {
|
|
|
28
31
|
document.title = `${this.errors.length} errors - ${document.title}`;
|
|
29
32
|
}
|
|
30
33
|
showSummary() {
|
|
31
|
-
this
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
34
|
+
this.$summary.innerHTML = this.getSummaryHtml();
|
|
35
|
+
this.$summary.classList.remove('moj-hidden');
|
|
36
|
+
this.$summary.setAttribute('aria-labelledby', 'errorSummary-heading');
|
|
37
|
+
this.$summary.focus();
|
|
35
38
|
}
|
|
36
39
|
getSummaryHtml() {
|
|
37
40
|
let html = '<h2 id="error-summary-title" class="govuk-error-summary__title">There is a problem</h2>';
|
|
@@ -49,9 +52,13 @@ class FormValidator {
|
|
|
49
52
|
return html;
|
|
50
53
|
}
|
|
51
54
|
hideSummary() {
|
|
52
|
-
this
|
|
53
|
-
this
|
|
55
|
+
this.$summary.classList.add('moj-hidden');
|
|
56
|
+
this.$summary.removeAttribute('aria-labelledby');
|
|
54
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {SubmitEvent} event - Form submit event
|
|
61
|
+
*/
|
|
55
62
|
onSubmit(event) {
|
|
56
63
|
this.removeInlineErrors();
|
|
57
64
|
this.hideSummary();
|
|
@@ -68,25 +75,29 @@ class FormValidator {
|
|
|
68
75
|
this.showInlineError(error);
|
|
69
76
|
}
|
|
70
77
|
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {ValidationError} error
|
|
81
|
+
*/
|
|
71
82
|
showInlineError(error) {
|
|
72
|
-
const errorSpan = document.createElement('span');
|
|
73
|
-
errorSpan.id = `${error.fieldName}-error`;
|
|
74
|
-
errorSpan.classList.add('govuk-error-message');
|
|
75
|
-
errorSpan.innerHTML = this.escapeHtml(error.message);
|
|
76
|
-
const control = document.querySelector(`#${error.fieldName}`);
|
|
77
|
-
const fieldset = control.closest('.govuk-fieldset');
|
|
78
|
-
const fieldContainer = (fieldset || control).closest('.govuk-form-group');
|
|
79
|
-
const label = fieldContainer.querySelector('label');
|
|
80
|
-
const legend = fieldContainer.querySelector('legend');
|
|
81
|
-
fieldContainer.classList.add('govuk-form-group--error');
|
|
82
|
-
if (fieldset && legend) {
|
|
83
|
-
legend.after(errorSpan);
|
|
84
|
-
fieldContainer.setAttribute('aria-invalid', 'true');
|
|
85
|
-
addAttributeValue(fieldset, 'aria-describedby', errorSpan.id);
|
|
86
|
-
} else if (label && control) {
|
|
87
|
-
label.after(errorSpan);
|
|
88
|
-
control.setAttribute('aria-invalid', 'true');
|
|
89
|
-
addAttributeValue(control, 'aria-describedby', errorSpan.id);
|
|
83
|
+
const $errorSpan = document.createElement('span');
|
|
84
|
+
$errorSpan.id = `${error.fieldName}-error`;
|
|
85
|
+
$errorSpan.classList.add('govuk-error-message');
|
|
86
|
+
$errorSpan.innerHTML = this.escapeHtml(error.message);
|
|
87
|
+
const $control = document.querySelector(`#${error.fieldName}`);
|
|
88
|
+
const $fieldset = $control.closest('.govuk-fieldset');
|
|
89
|
+
const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group');
|
|
90
|
+
const $label = $fieldContainer.querySelector('label');
|
|
91
|
+
const $legend = $fieldContainer.querySelector('legend');
|
|
92
|
+
$fieldContainer.classList.add('govuk-form-group--error');
|
|
93
|
+
if ($fieldset && $legend) {
|
|
94
|
+
$legend.after($errorSpan);
|
|
95
|
+
$fieldContainer.setAttribute('aria-invalid', 'true');
|
|
96
|
+
addAttributeValue($fieldset, 'aria-describedby', $errorSpan.id);
|
|
97
|
+
} else if ($label && $control) {
|
|
98
|
+
$label.after($errorSpan);
|
|
99
|
+
$control.setAttribute('aria-invalid', 'true');
|
|
100
|
+
addAttributeValue($control, 'aria-describedby', $errorSpan.id);
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
removeInlineErrors() {
|
|
@@ -94,33 +105,46 @@ class FormValidator {
|
|
|
94
105
|
this.removeInlineError(error);
|
|
95
106
|
}
|
|
96
107
|
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {ValidationError} error
|
|
111
|
+
*/
|
|
97
112
|
removeInlineError(error) {
|
|
98
|
-
const errorSpan = document.querySelector(`#${error.fieldName}-error`);
|
|
99
|
-
const control = document.querySelector(`#${error.fieldName}`);
|
|
100
|
-
const fieldset = control.closest('.govuk-fieldset');
|
|
101
|
-
const fieldContainer = (fieldset || control).closest('.govuk-form-group');
|
|
102
|
-
const label = fieldContainer.querySelector('label');
|
|
103
|
-
const legend = fieldContainer.querySelector('legend');
|
|
104
|
-
errorSpan.remove();
|
|
105
|
-
fieldContainer.classList.remove('govuk-form-group--error');
|
|
106
|
-
if (fieldset && legend) {
|
|
107
|
-
fieldContainer.removeAttribute('aria-invalid');
|
|
108
|
-
removeAttributeValue(fieldset, 'aria-describedby', errorSpan.id);
|
|
109
|
-
} else if (label && control) {
|
|
110
|
-
control.removeAttribute('aria-invalid');
|
|
111
|
-
removeAttributeValue(control, 'aria-describedby', errorSpan.id);
|
|
113
|
+
const $errorSpan = document.querySelector(`#${error.fieldName}-error`);
|
|
114
|
+
const $control = document.querySelector(`#${error.fieldName}`);
|
|
115
|
+
const $fieldset = $control.closest('.govuk-fieldset');
|
|
116
|
+
const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group');
|
|
117
|
+
const $label = $fieldContainer.querySelector('label');
|
|
118
|
+
const $legend = $fieldContainer.querySelector('legend');
|
|
119
|
+
$errorSpan.remove();
|
|
120
|
+
$fieldContainer.classList.remove('govuk-form-group--error');
|
|
121
|
+
if ($fieldset && $legend) {
|
|
122
|
+
$fieldContainer.removeAttribute('aria-invalid');
|
|
123
|
+
removeAttributeValue($fieldset, 'aria-describedby', $errorSpan.id);
|
|
124
|
+
} else if ($label && $control) {
|
|
125
|
+
$control.removeAttribute('aria-invalid');
|
|
126
|
+
removeAttributeValue($control, 'aria-describedby', $errorSpan.id);
|
|
112
127
|
}
|
|
113
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {string} fieldName - Field name
|
|
132
|
+
* @param {ValidationRule[]} rules - Validation rules
|
|
133
|
+
*/
|
|
114
134
|
addValidator(fieldName, rules) {
|
|
115
135
|
this.validators.push({
|
|
116
136
|
fieldName,
|
|
117
137
|
rules,
|
|
118
|
-
field: this.
|
|
138
|
+
field: this.$root.elements.namedItem(fieldName)
|
|
119
139
|
});
|
|
120
140
|
}
|
|
121
141
|
validate() {
|
|
122
142
|
this.errors = [];
|
|
143
|
+
|
|
144
|
+
/** @type {Validator | null} */
|
|
123
145
|
let validator = null;
|
|
146
|
+
|
|
147
|
+
/** @type {boolean | string} */
|
|
124
148
|
let validatorReturnValue = true;
|
|
125
149
|
let i;
|
|
126
150
|
let j;
|
|
@@ -145,11 +169,41 @@ class FormValidator {
|
|
|
145
169
|
}
|
|
146
170
|
return this.errors.length === 0;
|
|
147
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @type {Record<string, string>}
|
|
175
|
+
*/
|
|
148
176
|
}
|
|
149
177
|
|
|
150
178
|
/**
|
|
151
179
|
* @typedef {object} FormValidatorConfig
|
|
152
|
-
* @property {
|
|
180
|
+
* @property {object} [summary] - Error summary config
|
|
181
|
+
* @property {string} [summary.selector] - Selector for error summary
|
|
182
|
+
* @property {Element | null} [summary.element] - HTML element for error summary
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @typedef {object} ValidationRule
|
|
187
|
+
* @property {(field: Validator['field'], params: Record<string, Validator['field']>) => boolean | string} method - Validation method
|
|
188
|
+
* @property {string} message - Error message
|
|
189
|
+
* @property {Record<string, Validator['field']>} [params] - Parameters for validation
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @typedef {object} ValidationError
|
|
194
|
+
* @property {string} fieldName - Name of the field
|
|
195
|
+
* @property {string} message - Validation error message
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @typedef {object} Validator
|
|
200
|
+
* @property {string} fieldName - Name of the field
|
|
201
|
+
* @property {ValidationRule[]} rules - Validation rules
|
|
202
|
+
* @property {Element | RadioNodeList} field - Form field
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'
|
|
153
207
|
*/
|
|
154
208
|
FormValidator.entityMap = {
|
|
155
209
|
'&': '&',
|
|
@@ -161,6 +215,32 @@ FormValidator.entityMap = {
|
|
|
161
215
|
'`': '`',
|
|
162
216
|
'=': '='
|
|
163
217
|
};
|
|
218
|
+
/**
|
|
219
|
+
* Name for the component used when initialising using data-module attributes.
|
|
220
|
+
*/
|
|
221
|
+
FormValidator.moduleName = 'moj-form-validator';
|
|
222
|
+
/**
|
|
223
|
+
* Multi file upload default config
|
|
224
|
+
*
|
|
225
|
+
* @type {FormValidatorConfig}
|
|
226
|
+
*/
|
|
227
|
+
FormValidator.defaults = Object.freeze({
|
|
228
|
+
summary: {
|
|
229
|
+
selector: '.govuk-error-summary'
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Multi file upload config schema
|
|
234
|
+
*
|
|
235
|
+
* @satisfies {Schema<FormValidatorConfig>}
|
|
236
|
+
*/
|
|
237
|
+
FormValidator.schema = Object.freeze(/** @type {const} */{
|
|
238
|
+
properties: {
|
|
239
|
+
summary: {
|
|
240
|
+
type: 'object'
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
164
244
|
|
|
165
245
|
export { FormValidator };
|
|
166
246
|
//# sourceMappingURL=form-validator.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-validator.mjs","sources":["../../../../src/moj/components/form-validator/form-validator.mjs"],"sourcesContent":["import { addAttributeValue, removeAttributeValue } from '../../helpers.mjs'\n\nexport class FormValidator {\n /**\n * @param {Element | null} form - HTML element to use for form validator\n * @param {FormValidatorConfig} [config] - Button menu config\n */\n constructor(form, config = {}) {\n if (!form || !(form instanceof HTMLFormElement)) {\n return this\n }\n\n this.form = form\n this.errors = []\n this.validators = []\n this.form.addEventListener('submit', this.onSubmit.bind(this))\n this.summary =\n config.summary || document.querySelector('.govuk-error-summary')\n this.originalTitle = document.title\n }\n\n escapeHtml(string) {\n return String(string).replace(/[&<>\"'`=/]/g, function fromEntityMap(s) {\n return FormValidator.entityMap[s]\n })\n }\n\n resetTitle() {\n document.title = this.originalTitle\n }\n\n updateTitle() {\n document.title = `${this.errors.length} errors - ${document.title}`\n }\n\n showSummary() {\n this.summary.innerHTML = this.getSummaryHtml()\n this.summary.classList.remove('moj-hidden')\n this.summary.setAttribute('aria-labelledby', 'errorSummary-heading')\n this.summary.focus()\n }\n\n getSummaryHtml() {\n let html =\n '<h2 id=\"error-summary-title\" class=\"govuk-error-summary__title\">There is a problem</h2>'\n html += '<div class=\"govuk-error-summary__body\">'\n html += '<ul class=\"govuk-list govuk-error-summary__list\">'\n for (const error of this.errors) {\n html += '<li>'\n html += `<a href=\"#${this.escapeHtml(error.fieldName)}\">`\n html += this.escapeHtml(error.message)\n html += '</a>'\n html += '</li>'\n }\n html += '</ul>'\n html += '</div>'\n return html\n }\n\n hideSummary() {\n this.summary.classList.add('moj-hidden')\n this.summary.removeAttribute('aria-labelledby')\n }\n\n onSubmit(event) {\n this.removeInlineErrors()\n this.hideSummary()\n this.resetTitle()\n if (!this.validate()) {\n event.preventDefault()\n this.updateTitle()\n this.showSummary()\n this.showInlineErrors()\n }\n }\n\n showInlineErrors() {\n for (const error of this.errors) {\n this.showInlineError(error)\n }\n }\n\n showInlineError(error) {\n const errorSpan = document.createElement('span')\n errorSpan.id = `${error.fieldName}-error`\n errorSpan.classList.add('govuk-error-message')\n errorSpan.innerHTML = this.escapeHtml(error.message)\n\n const control = document.querySelector(`#${error.fieldName}`)\n const fieldset = control.closest('.govuk-fieldset')\n const fieldContainer = (fieldset || control).closest('.govuk-form-group')\n\n const label = fieldContainer.querySelector('label')\n const legend = fieldContainer.querySelector('legend')\n\n fieldContainer.classList.add('govuk-form-group--error')\n\n if (fieldset && legend) {\n legend.after(errorSpan)\n fieldContainer.setAttribute('aria-invalid', 'true')\n addAttributeValue(fieldset, 'aria-describedby', errorSpan.id)\n } else if (label && control) {\n label.after(errorSpan)\n control.setAttribute('aria-invalid', 'true')\n addAttributeValue(control, 'aria-describedby', errorSpan.id)\n }\n }\n\n removeInlineErrors() {\n for (const error of this.errors) {\n this.removeInlineError(error)\n }\n }\n\n removeInlineError(error) {\n const errorSpan = document.querySelector(`#${error.fieldName}-error`)\n\n const control = document.querySelector(`#${error.fieldName}`)\n const fieldset = control.closest('.govuk-fieldset')\n const fieldContainer = (fieldset || control).closest('.govuk-form-group')\n\n const label = fieldContainer.querySelector('label')\n const legend = fieldContainer.querySelector('legend')\n\n errorSpan.remove()\n fieldContainer.classList.remove('govuk-form-group--error')\n\n if (fieldset && legend) {\n fieldContainer.removeAttribute('aria-invalid')\n removeAttributeValue(fieldset, 'aria-describedby', errorSpan.id)\n } else if (label && control) {\n control.removeAttribute('aria-invalid')\n removeAttributeValue(control, 'aria-describedby', errorSpan.id)\n }\n }\n\n addValidator(fieldName, rules) {\n this.validators.push({\n fieldName,\n rules,\n field: this.form.elements[fieldName]\n })\n }\n\n validate() {\n this.errors = []\n let validator = null\n let validatorReturnValue = true\n let i\n let j\n for (i = 0; i < this.validators.length; i++) {\n validator = this.validators[i]\n for (j = 0; j < validator.rules.length; j++) {\n validatorReturnValue = validator.rules[j].method(\n validator.field,\n validator.rules[j].params\n )\n\n if (\n typeof validatorReturnValue === 'boolean' &&\n !validatorReturnValue\n ) {\n this.errors.push({\n fieldName: validator.fieldName,\n message: validator.rules[j].message\n })\n break\n } else if (typeof validatorReturnValue === 'string') {\n this.errors.push({\n fieldName: validatorReturnValue,\n message: validator.rules[j].message\n })\n break\n }\n }\n }\n return this.errors.length === 0\n }\n\n static entityMap = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '/': '/',\n '`': '`',\n '=': '='\n }\n}\n\n/**\n * @typedef {object} FormValidatorConfig\n * @property {HTMLElement} [summary] - HTML element to use for error summary\n */\n"],"names":["FormValidator","constructor","form","config","HTMLFormElement","errors","validators","addEventListener","onSubmit","bind","summary","document","querySelector","originalTitle","title","escapeHtml","string","String","replace","fromEntityMap","s","entityMap","resetTitle","updateTitle","length","showSummary","innerHTML","getSummaryHtml","classList","remove","setAttribute","focus","html","error","fieldName","message","hideSummary","add","removeAttribute","event","removeInlineErrors","validate","preventDefault","showInlineErrors","showInlineError","errorSpan","createElement","id","control","fieldset","closest","fieldContainer","label","legend","after","addAttributeValue","removeInlineError","removeAttributeValue","addValidator","rules","push","field","elements","validator","validatorReturnValue","i","j","method","params"],"mappings":";;AAEO,MAAMA,aAAa,CAAC;AACzB;AACF;AACA;AACA;AACEC,EAAAA,WAAWA,CAACC,IAAI,EAAEC,MAAM,GAAG,EAAE,EAAE;IAC7B,IAAI,CAACD,IAAI,IAAI,EAAEA,IAAI,YAAYE,eAAe,CAAC,EAAE;AAC/C,MAAA,OAAO,IAAI;AACb;IAEA,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACG,MAAM,GAAG,EAAE;IAChB,IAAI,CAACC,UAAU,GAAG,EAAE;AACpB,IAAA,IAAI,CAACJ,IAAI,CAACK,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAACC,QAAQ,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D,IAAA,IAAI,CAACC,OAAO,GACVP,MAAM,CAACO,OAAO,IAAIC,QAAQ,CAACC,aAAa,CAAC,sBAAsB,CAAC;AAClE,IAAA,IAAI,CAACC,aAAa,GAAGF,QAAQ,CAACG,KAAK;AACrC;EAEAC,UAAUA,CAACC,MAAM,EAAE;AACjB,IAAA,OAAOC,MAAM,CAACD,MAAM,CAAC,CAACE,OAAO,CAAC,aAAa,EAAE,SAASC,aAAaA,CAACC,CAAC,EAAE;AACrE,MAAA,OAAOpB,aAAa,CAACqB,SAAS,CAACD,CAAC,CAAC;AACnC,KAAC,CAAC;AACJ;AAEAE,EAAAA,UAAUA,GAAG;AACXX,IAAAA,QAAQ,CAACG,KAAK,GAAG,IAAI,CAACD,aAAa;AACrC;AAEAU,EAAAA,WAAWA,GAAG;AACZZ,IAAAA,QAAQ,CAACG,KAAK,GAAG,CAAA,EAAG,IAAI,CAACT,MAAM,CAACmB,MAAM,CAAA,UAAA,EAAab,QAAQ,CAACG,KAAK,CAAE,CAAA;AACrE;AAEAW,EAAAA,WAAWA,GAAG;IACZ,IAAI,CAACf,OAAO,CAACgB,SAAS,GAAG,IAAI,CAACC,cAAc,EAAE;IAC9C,IAAI,CA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AS;AAC9BC,YAAAA,OAAO,EAAE4B,SAAS,CAACJ,KAAK,CAACO,CAAC,CAAC,CAAC/B;AAC9B,WAAC,CAAC;AACF,UAAA;AACF,SAAC,MAAM,IAAI,OAAO6B,oBAAoB,KAAK,QAAQ,EAAE;AACnD,UAAA,IAAI,CAAC3D,MAAM,CAACuD,IAAI,CAAC;AACf1B,YAAAA,SAAS,EAAE8B,oBAAoB;AAC/B7B,YAAAA,OAAO,EAAE4B,SAAS,CAACJ,KAAK,CAACO,CAAC,CAAC,CAAC/B;AAC9B,WAAC,CAAC;AACF,UAAA;AACF;AACF;AACF;AACA,IAAA,OAAO,IAAI,CAAC9B,MAAM,CAACmB,MAAM,KAAK,CAAC;AACjC;AAYF;;AAEA;AACA;AACA;AACA;AAhMaxB,aAAa,CAiLjBqB,SAAS,GAAG;AACjB,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,MAAM;AACX,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,OAAO;AACZ,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE,QAAQ;AACb,EAAA,GAAG,EAAE;AACP,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"form-validator.mjs","sources":["../../../../src/moj/components/form-validator/form-validator.mjs"],"sourcesContent":["import { ConfigurableComponent } from 'govuk-frontend'\n\nimport { addAttributeValue, removeAttributeValue } from '../../helpers.mjs'\n\n/**\n * @augments {ConfigurableComponent<FormValidatorConfig, HTMLFormElement>}\n */\nexport class FormValidator extends ConfigurableComponent {\n /**\n * @param {Element | null} $root - HTML element to use for form validator\n * @param {FormValidatorConfig} [config] - Form validator config\n */\n constructor($root, config = {}) {\n super($root, config)\n\n const $summary =\n this.config.summary.element ||\n document.querySelector(this.config.summary.selector)\n\n if (!$summary || !($summary instanceof HTMLElement)) {\n return this\n }\n\n this.$summary = $summary\n\n this.errors = /** @type {ValidationError[]} */ ([])\n this.validators = /** @type {Validator[]} */ ([])\n this.originalTitle = document.title\n\n this.$root.addEventListener('submit', this.onSubmit.bind(this))\n }\n\n escapeHtml(string = '') {\n return String(string).replace(\n /[&<>\"'`=/]/g,\n (name) => FormValidator.entityMap[name]\n )\n }\n\n resetTitle() {\n document.title = this.originalTitle\n }\n\n updateTitle() {\n document.title = `${this.errors.length} errors - ${document.title}`\n }\n\n showSummary() {\n this.$summary.innerHTML = this.getSummaryHtml()\n this.$summary.classList.remove('moj-hidden')\n this.$summary.setAttribute('aria-labelledby', 'errorSummary-heading')\n this.$summary.focus()\n }\n\n getSummaryHtml() {\n let html =\n '<h2 id=\"error-summary-title\" class=\"govuk-error-summary__title\">There is a problem</h2>'\n html += '<div class=\"govuk-error-summary__body\">'\n html += '<ul class=\"govuk-list govuk-error-summary__list\">'\n for (const error of this.errors) {\n html += '<li>'\n html += `<a href=\"#${this.escapeHtml(error.fieldName)}\">`\n html += this.escapeHtml(error.message)\n html += '</a>'\n html += '</li>'\n }\n html += '</ul>'\n html += '</div>'\n return html\n }\n\n hideSummary() {\n this.$summary.classList.add('moj-hidden')\n this.$summary.removeAttribute('aria-labelledby')\n }\n\n /**\n * @param {SubmitEvent} event - Form submit event\n */\n onSubmit(event) {\n this.removeInlineErrors()\n this.hideSummary()\n this.resetTitle()\n if (!this.validate()) {\n event.preventDefault()\n this.updateTitle()\n this.showSummary()\n this.showInlineErrors()\n }\n }\n\n showInlineErrors() {\n for (const error of this.errors) {\n this.showInlineError(error)\n }\n }\n\n /**\n * @param {ValidationError} error\n */\n showInlineError(error) {\n const $errorSpan = document.createElement('span')\n $errorSpan.id = `${error.fieldName}-error`\n $errorSpan.classList.add('govuk-error-message')\n $errorSpan.innerHTML = this.escapeHtml(error.message)\n\n const $control = document.querySelector(`#${error.fieldName}`)\n const $fieldset = $control.closest('.govuk-fieldset')\n const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group')\n\n const $label = $fieldContainer.querySelector('label')\n const $legend = $fieldContainer.querySelector('legend')\n\n $fieldContainer.classList.add('govuk-form-group--error')\n\n if ($fieldset && $legend) {\n $legend.after($errorSpan)\n $fieldContainer.setAttribute('aria-invalid', 'true')\n addAttributeValue($fieldset, 'aria-describedby', $errorSpan.id)\n } else if ($label && $control) {\n $label.after($errorSpan)\n $control.setAttribute('aria-invalid', 'true')\n addAttributeValue($control, 'aria-describedby', $errorSpan.id)\n }\n }\n\n removeInlineErrors() {\n for (const error of this.errors) {\n this.removeInlineError(error)\n }\n }\n\n /**\n * @param {ValidationError} error\n */\n removeInlineError(error) {\n const $errorSpan = document.querySelector(`#${error.fieldName}-error`)\n\n const $control = document.querySelector(`#${error.fieldName}`)\n const $fieldset = $control.closest('.govuk-fieldset')\n const $fieldContainer = ($fieldset || $control).closest('.govuk-form-group')\n\n const $label = $fieldContainer.querySelector('label')\n const $legend = $fieldContainer.querySelector('legend')\n\n $errorSpan.remove()\n $fieldContainer.classList.remove('govuk-form-group--error')\n\n if ($fieldset && $legend) {\n $fieldContainer.removeAttribute('aria-invalid')\n removeAttributeValue($fieldset, 'aria-describedby', $errorSpan.id)\n } else if ($label && $control) {\n $control.removeAttribute('aria-invalid')\n removeAttributeValue($control, 'aria-describedby', $errorSpan.id)\n }\n }\n\n /**\n * @param {string} fieldName - Field name\n * @param {ValidationRule[]} rules - Validation rules\n */\n addValidator(fieldName, rules) {\n this.validators.push({\n fieldName,\n rules,\n field: this.$root.elements.namedItem(fieldName)\n })\n }\n\n validate() {\n this.errors = []\n\n /** @type {Validator | null} */\n let validator = null\n\n /** @type {boolean | string} */\n let validatorReturnValue = true\n\n let i\n let j\n\n for (i = 0; i < this.validators.length; i++) {\n validator = this.validators[i]\n for (j = 0; j < validator.rules.length; j++) {\n validatorReturnValue = validator.rules[j].method(\n validator.field,\n validator.rules[j].params\n )\n\n if (\n typeof validatorReturnValue === 'boolean' &&\n !validatorReturnValue\n ) {\n this.errors.push({\n fieldName: validator.fieldName,\n message: validator.rules[j].message\n })\n break\n } else if (typeof validatorReturnValue === 'string') {\n this.errors.push({\n fieldName: validatorReturnValue,\n message: validator.rules[j].message\n })\n break\n }\n }\n }\n return this.errors.length === 0\n }\n\n /**\n * @type {Record<string, string>}\n */\n static entityMap = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '/': '/',\n '`': '`',\n '=': '='\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-form-validator'\n\n /**\n * Multi file upload default config\n *\n * @type {FormValidatorConfig}\n */\n static defaults = Object.freeze({\n summary: {\n selector: '.govuk-error-summary'\n }\n })\n\n /**\n * Multi file upload config schema\n *\n * @satisfies {Schema<FormValidatorConfig>}\n */\n static schema = Object.freeze(\n /** @type {const} */ ({\n properties: {\n summary: { type: 'object' }\n }\n })\n )\n}\n\n/**\n * @typedef {object} FormValidatorConfig\n * @property {object} [summary] - Error summary config\n * @property {string} [summary.selector] - Selector for error summary\n * @property {Element | null} [summary.element] - HTML element for error summary\n */\n\n/**\n * @typedef {object} ValidationRule\n * @property {(field: Validator['field'], params: Record<string, Validator['field']>) => boolean | string} method - Validation method\n * @property {string} message - Error message\n * @property {Record<string, Validator['field']>} [params] - Parameters for validation\n */\n\n/**\n * @typedef {object} ValidationError\n * @property {string} fieldName - Name of the field\n * @property {string} message - Validation error message\n */\n\n/**\n * @typedef {object} Validator\n * @property {string} fieldName - Name of the field\n * @property {ValidationRule[]} rules - Validation rules\n * @property {Element | RadioNodeList} field - Form field\n */\n\n/**\n * @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'\n */\n"],"names":["FormValidator","ConfigurableComponent","constructor","$root","config","$summary","summary","element","document","querySelector","selector","HTMLElement","errors","validators","originalTitle","title","addEventListener","onSubmit","bind","escapeHtml","string","String","replace","name","entityMap","resetTitle","updateTitle","length","showSummary","innerHTML","getSummaryHtml","classList","remove","setAttribute","focus","html","error","fieldName","message","hideSummary","add","removeAttribute","event","removeInlineErrors","validate","preventDefault","showInlineErrors","showInlineError","$errorSpan","createElement","id","$control","$fieldset","closest","$fieldContainer","$label","$legend","after","addAttributeValue","removeInlineError","removeAttributeValue","addValidator","rules","push","field","elements","namedItem","validator","validatorReturnValue","i","j","method","params","moduleName","defaults","Object","freeze","schema","properties","type"],"mappings":";;;AAIA;AACA;AACA;AACO,MAAMA,aAAa,SAASC,qBAAqB,CAAC;AACvD;AACF;AACA;AACA;AACEC,EAAAA,WAAWA,CAACC,KAAK,EAAEC,MAAM,GAAG,EAAE,EAAE;AAC9B,IAAA,KAAK,CAACD,KAAK,EAAEC,MAAM,CAAC;IAEpB,MAAMC,QAAQ,GACZ,IAAI,CAACD,MAAM,CAACE,OAAO,CAACC,OAAO,IAC3BC,QAAQ,CAACC,aAAa,CAAC,IAAI,CAACL,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC;IAEtD,IAAI,CAACL,QAAQ,IAAI,EAAEA,QAAQ,YAAYM,WAAW,CAAC,EAAE;AACnD,MAAA,OAAO,IAAI;AACb;IAEA,IAAI,CAACN,QAAQ,GAAGA,QAAQ;AAExB,IAAA,IAAI,CAACO,MAAM,mCAAqC,EAAG;AACnD,IAAA,IAAI,CAACC,UAAU,6BAA+B,EAAG;AACjD,IAAA,IAAI,CAACC,aAAa,GAAGN,QAAQ,CAACO,KAAK;AAEnC,IAAA,IAAI,CAACZ,KAAK,CAACa,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAACC,QAAQ,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjE;AAEAC,EAAAA,UAAUA,CAACC,MAAM,GAAG,EAAE,EAAE;AACtB,IAAA,OAAOC,MAAM,CAACD,MAAM,CAAC,CAACE,OAAO,CAC3B,aAAa,EACZC,IAAI,IAAKvB,aAAa,CAACwB,SAAS,CAACD,IAAI,CACxC,CAAC;AACH;AAEAE,EAAAA,UAAUA,GAAG;AACXjB,IAAAA,QAAQ,CAACO,KAAK,GAAG,IAAI,CAACD,aAAa;AACrC;AAEAY,EAAAA,WAAWA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