@ministryofjustice/frontend 3.3.1 → 3.5.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/README.md +4 -10
- package/govuk-prototype-kit.config.json +5 -16
- package/moj/all.jquery.min.js +15 -4
- package/moj/all.js +2856 -2280
- package/moj/all.scss +2 -0
- package/moj/components/_all.scss +1 -0
- package/moj/components/action-bar/_action-bar.scss +4 -6
- package/moj/components/add-another/_add-another.scss +9 -7
- package/moj/components/add-another/add-another.js +128 -76
- package/moj/components/alert/README.md +0 -0
- package/moj/components/alert/_alert.scss +142 -0
- package/moj/components/alert/alert.js +482 -0
- package/moj/components/alert/alert.spec.helper.js +92 -0
- package/moj/components/alert/macro.njk +3 -0
- package/moj/components/alert/template.njk +83 -0
- package/moj/components/badge/_badge.scss +3 -4
- package/moj/components/banner/_banner.scss +5 -10
- package/moj/components/button-menu/_button-menu.scss +10 -9
- package/moj/components/button-menu/button-menu.js +348 -318
- package/moj/components/cookie-banner/_cookie-banner.scss +6 -5
- package/moj/components/currency-input/_currency-input.scss +4 -4
- package/moj/components/date-picker/README.md +14 -17
- package/moj/components/date-picker/_date-picker.scss +122 -106
- package/moj/components/date-picker/date-picker.js +927 -900
- package/moj/components/filter/README.md +1 -1
- package/moj/components/filter/_filter.scss +53 -75
- package/moj/components/filter-toggle-button/filter-toggle-button.js +122 -87
- package/moj/components/form-validator/form-validator.js +399 -156
- package/moj/components/header/_header.scss +17 -19
- package/moj/components/identity-bar/_identity-bar.scss +5 -5
- package/moj/components/interruption-card/_interruption-card.scss +2 -2
- package/moj/components/messages/_messages.scss +12 -19
- package/moj/components/multi-file-upload/README.md +1 -1
- package/moj/components/multi-file-upload/_multi-file-upload.scss +34 -30
- package/moj/components/multi-file-upload/multi-file-upload.js +454 -183
- package/moj/components/multi-select/_multi-select.scss +4 -3
- package/moj/components/multi-select/multi-select.js +106 -70
- package/moj/components/notification-badge/_notification-badge.scss +12 -12
- package/moj/components/organisation-switcher/_organisation-switcher.scss +1 -1
- package/moj/components/page-header-actions/_page-header-actions.scss +3 -2
- package/moj/components/pagination/_pagination.scss +26 -31
- package/moj/components/password-reveal/_password-reveal.scss +1 -2
- package/moj/components/password-reveal/password-reveal.js +63 -31
- package/moj/components/primary-navigation/_primary-navigation.scss +26 -29
- package/moj/components/progress-bar/_progress-bar.scss +21 -26
- package/moj/components/rich-text-editor/_rich-text-editor.scss +17 -16
- package/moj/components/rich-text-editor/rich-text-editor.js +186 -139
- package/moj/components/search/_search.scss +6 -4
- package/moj/components/search-toggle/search-toggle.js +83 -53
- package/moj/components/search-toggle/search-toggle.scss +21 -15
- package/moj/components/side-navigation/_side-navigation.scss +12 -21
- package/moj/components/sortable-table/_sortable-table.scss +25 -23
- package/moj/components/sortable-table/sortable-table.js +162 -119
- package/moj/components/sub-navigation/_sub-navigation.scss +24 -28
- package/moj/components/tag/_tag.scss +8 -9
- package/moj/components/task-list/_task-list.scss +8 -7
- package/moj/components/ticket-panel/_ticket-panel.scss +14 -6
- package/moj/components/timeline/_timeline.scss +18 -20
- package/moj/filters/all.js +28 -30
- package/moj/filters/prototype-kit-13-filters.js +2 -1
- package/moj/helpers/_all.scss +1 -0
- package/moj/helpers/_hidden.scss +1 -1
- package/moj/helpers/_links.scss +20 -0
- package/moj/helpers.js +218 -51
- package/moj/init.js +2 -2
- package/moj/moj-frontend.min.css +2 -2
- package/moj/moj-frontend.min.js +15 -4
- package/moj/objects/_filter-layout.scss +11 -10
- package/moj/objects/_scrollable-pane.scss +11 -14
- package/moj/settings/_colours.scss +5 -0
- package/moj/settings/_measurements.scss +0 -2
- package/moj/utilities/_hidden.scss +3 -3
- package/moj/utilities/_width-container.scss +1 -1
- package/moj/version.js +28 -1
- package/package.json +1 -1
- package/moj/all.spec.js +0 -22
- package/moj/components/button-menu/button-menu.spec.js +0 -361
- package/moj/components/date-picker/date-picker.spec.js +0 -1130
- package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -304
- package/moj/components/multi-select/multi-select.spec.js +0 -135
- package/moj/components/password-reveal/password-reveal.spec.js +0 -55
- package/moj/components/search-toggle/search-toggle.spec.js +0 -134
- package/moj/namespace.js +0 -1
|
@@ -1,156 +1,399 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MOJFrontend = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var _global_window_jQuery = window.jQuery;
|
|
12
|
+
|
|
13
|
+
var helpers;
|
|
14
|
+
var hasRequiredHelpers;
|
|
15
|
+
|
|
16
|
+
function requireHelpers () {
|
|
17
|
+
if (hasRequiredHelpers) return helpers;
|
|
18
|
+
hasRequiredHelpers = 1;
|
|
19
|
+
function removeAttributeValue(el, attr, value) {
|
|
20
|
+
let re, m;
|
|
21
|
+
if (el.getAttribute(attr)) {
|
|
22
|
+
if (el.getAttribute(attr) === value) {
|
|
23
|
+
el.removeAttribute(attr);
|
|
24
|
+
} else {
|
|
25
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
26
|
+
m = el.getAttribute(attr).match(re);
|
|
27
|
+
if (m && m.length === 3) {
|
|
28
|
+
el.setAttribute(
|
|
29
|
+
attr,
|
|
30
|
+
el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function addAttributeValue(el, attr, value) {
|
|
38
|
+
let re;
|
|
39
|
+
if (!el.getAttribute(attr)) {
|
|
40
|
+
el.setAttribute(attr, value);
|
|
41
|
+
} else {
|
|
42
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
43
|
+
if (!re.test(el.getAttribute(attr))) {
|
|
44
|
+
el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function dragAndDropSupported() {
|
|
50
|
+
const div = document.createElement('div');
|
|
51
|
+
return typeof div.ondrop !== 'undefined'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function formDataSupported() {
|
|
55
|
+
return typeof FormData === 'function'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fileApiSupported() {
|
|
59
|
+
const input = document.createElement('input');
|
|
60
|
+
input.type = 'file';
|
|
61
|
+
return typeof input.files !== 'undefined'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function nodeListForEach(nodes, callback) {
|
|
65
|
+
if (window.NodeList.prototype.forEach) {
|
|
66
|
+
return nodes.forEach(callback)
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
69
|
+
callback.call(window, nodes[i], i, nodes);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Find an elements next sibling
|
|
75
|
+
*
|
|
76
|
+
* Utility function to find an elements next sibling matching the provided
|
|
77
|
+
* selector.
|
|
78
|
+
*
|
|
79
|
+
* @param {HTMLElement} $element - Element to find siblings for
|
|
80
|
+
* @param {string} selector - selector for required sibling
|
|
81
|
+
*/
|
|
82
|
+
function getNextSibling($element, selector) {
|
|
83
|
+
if (!$element) return
|
|
84
|
+
// Get the next sibling element
|
|
85
|
+
let $sibling = $element.nextElementSibling;
|
|
86
|
+
|
|
87
|
+
// If there's no selector, return the first sibling
|
|
88
|
+
if (!selector) return $sibling
|
|
89
|
+
|
|
90
|
+
// If the sibling matches our selector, use it
|
|
91
|
+
// If not, jump to the next sibling and continue the loop
|
|
92
|
+
while ($sibling) {
|
|
93
|
+
if ($sibling.matches(selector)) return $sibling
|
|
94
|
+
$sibling = $sibling.nextElementSibling;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Find an elements preceding sibling
|
|
100
|
+
*
|
|
101
|
+
* Utility function to find an elements previous sibling matching the provided
|
|
102
|
+
* selector.
|
|
103
|
+
*
|
|
104
|
+
* @param {HTMLElement} $element - Element to find siblings for
|
|
105
|
+
* @param {string} selector - selector for required sibling
|
|
106
|
+
*/
|
|
107
|
+
function getPreviousSibling($element, selector) {
|
|
108
|
+
if (!$element) return
|
|
109
|
+
// Get the previous sibling element
|
|
110
|
+
let $sibling = $element.previousElementSibling;
|
|
111
|
+
|
|
112
|
+
// If there's no selector, return the first sibling
|
|
113
|
+
if (!selector) return $sibling
|
|
114
|
+
|
|
115
|
+
// If the sibling matches our selector, use it
|
|
116
|
+
// If not, jump to the next sibling and continue the loop
|
|
117
|
+
while ($sibling) {
|
|
118
|
+
if ($sibling.matches(selector)) return $sibling
|
|
119
|
+
$sibling = $sibling.previousElementSibling;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function findNearestMatchingElement($element, selector) {
|
|
124
|
+
// If no element or selector is provided, return null
|
|
125
|
+
if (!$element) return
|
|
126
|
+
if (!selector) return
|
|
127
|
+
|
|
128
|
+
// Start with the current element
|
|
129
|
+
let $currentElement = $element;
|
|
130
|
+
|
|
131
|
+
while ($currentElement) {
|
|
132
|
+
// First check the current element
|
|
133
|
+
if ($currentElement.matches(selector)) {
|
|
134
|
+
return $currentElement
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Check all previous siblings
|
|
138
|
+
let $sibling = $currentElement.previousElementSibling;
|
|
139
|
+
while ($sibling) {
|
|
140
|
+
// Check if the sibling itself is a heading
|
|
141
|
+
if ($sibling.matches(selector)) {
|
|
142
|
+
return $sibling
|
|
143
|
+
}
|
|
144
|
+
$sibling = $sibling.previousElementSibling;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// If no match found in siblings, move up to parent
|
|
148
|
+
$currentElement = $currentElement.parentElement;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Move focus to element
|
|
154
|
+
*
|
|
155
|
+
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
156
|
+
* but removes it on blur as the element doesn't need to be focused again.
|
|
157
|
+
*
|
|
158
|
+
* @param {HTMLElement} $element - HTML element
|
|
159
|
+
* @param {object} [options] - Handler options
|
|
160
|
+
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
161
|
+
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
162
|
+
*/
|
|
163
|
+
function setFocus($element, options = {}) {
|
|
164
|
+
const isFocusable = $element.getAttribute('tabindex');
|
|
165
|
+
|
|
166
|
+
if (!isFocusable) {
|
|
167
|
+
$element.setAttribute('tabindex', '-1');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Handle element focus
|
|
172
|
+
*/
|
|
173
|
+
function onFocus() {
|
|
174
|
+
$element.addEventListener('blur', onBlur, { once: true });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Handle element blur
|
|
179
|
+
*/
|
|
180
|
+
function onBlur() {
|
|
181
|
+
if (options.onBlur) {
|
|
182
|
+
options.onBlur.call($element);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!isFocusable) {
|
|
186
|
+
$element.removeAttribute('tabindex');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Add listener to reset element on blur, after focus
|
|
191
|
+
$element.addEventListener('focus', onFocus, { once: true });
|
|
192
|
+
|
|
193
|
+
// Focus element
|
|
194
|
+
if (options.onBeforeFocus) {
|
|
195
|
+
options.onBeforeFocus.call($element);
|
|
196
|
+
}
|
|
197
|
+
$element.focus();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
helpers = {
|
|
201
|
+
removeAttributeValue,
|
|
202
|
+
addAttributeValue,
|
|
203
|
+
dragAndDropSupported,
|
|
204
|
+
formDataSupported,
|
|
205
|
+
fileApiSupported,
|
|
206
|
+
nodeListForEach,
|
|
207
|
+
getNextSibling,
|
|
208
|
+
getPreviousSibling,
|
|
209
|
+
findNearestMatchingElement,
|
|
210
|
+
setFocus
|
|
211
|
+
};
|
|
212
|
+
return helpers;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var formValidator$1;
|
|
216
|
+
var hasRequiredFormValidator;
|
|
217
|
+
|
|
218
|
+
function requireFormValidator () {
|
|
219
|
+
if (hasRequiredFormValidator) return formValidator$1;
|
|
220
|
+
hasRequiredFormValidator = 1;
|
|
221
|
+
const $ = _global_window_jQuery;
|
|
222
|
+
|
|
223
|
+
const { addAttributeValue, removeAttributeValue } = requireHelpers();
|
|
224
|
+
|
|
225
|
+
function FormValidator(form, options) {
|
|
226
|
+
this.form = form;
|
|
227
|
+
this.errors = [];
|
|
228
|
+
this.validators = [];
|
|
229
|
+
$(this.form).on('submit', $.proxy(this, 'onSubmit'));
|
|
230
|
+
this.summary =
|
|
231
|
+
options && options.summary ? $(options.summary) : $('.govuk-error-summary');
|
|
232
|
+
this.originalTitle = document.title;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
FormValidator.entityMap = {
|
|
236
|
+
'&': '&',
|
|
237
|
+
'<': '<',
|
|
238
|
+
'>': '>',
|
|
239
|
+
'"': '"',
|
|
240
|
+
"'": ''',
|
|
241
|
+
'/': '/',
|
|
242
|
+
'`': '`',
|
|
243
|
+
'=': '='
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
FormValidator.prototype.escapeHtml = function (string) {
|
|
247
|
+
return String(string).replace(/[&<>"'`=/]/g, function fromEntityMap(s) {
|
|
248
|
+
return FormValidator.entityMap[s]
|
|
249
|
+
})
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
FormValidator.prototype.resetTitle = function () {
|
|
253
|
+
document.title = this.originalTitle;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
FormValidator.prototype.updateTitle = function () {
|
|
257
|
+
document.title = `${this.errors.length} errors - ${document.title}`;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
FormValidator.prototype.showSummary = function () {
|
|
261
|
+
this.summary.html(this.getSummaryHtml());
|
|
262
|
+
this.summary.removeClass('moj-hidden');
|
|
263
|
+
this.summary.attr('aria-labelledby', 'errorSummary-heading');
|
|
264
|
+
this.summary.focus();
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
FormValidator.prototype.getSummaryHtml = function () {
|
|
268
|
+
let html =
|
|
269
|
+
'<h2 id="error-summary-title" class="govuk-error-summary__title">There is a problem</h2>';
|
|
270
|
+
html += '<div class="govuk-error-summary__body">';
|
|
271
|
+
html += '<ul class="govuk-list govuk-error-summary__list">';
|
|
272
|
+
for (let i = 0, j = this.errors.length; i < j; i++) {
|
|
273
|
+
const error = this.errors[i];
|
|
274
|
+
html += '<li>';
|
|
275
|
+
html += `<a href="#${this.escapeHtml(error.fieldName)}">`;
|
|
276
|
+
html += this.escapeHtml(error.message);
|
|
277
|
+
html += '</a>';
|
|
278
|
+
html += '</li>';
|
|
279
|
+
}
|
|
280
|
+
html += '</ul>';
|
|
281
|
+
html += '</div>';
|
|
282
|
+
return html
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
FormValidator.prototype.hideSummary = function () {
|
|
286
|
+
this.summary.addClass('moj-hidden');
|
|
287
|
+
this.summary.removeAttr('aria-labelledby');
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
FormValidator.prototype.onSubmit = function (e) {
|
|
291
|
+
this.removeInlineErrors();
|
|
292
|
+
this.hideSummary();
|
|
293
|
+
this.resetTitle();
|
|
294
|
+
if (!this.validate()) {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
this.updateTitle();
|
|
297
|
+
this.showSummary();
|
|
298
|
+
this.showInlineErrors();
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
FormValidator.prototype.showInlineErrors = function () {
|
|
303
|
+
for (let i = 0, j = this.errors.length; i < j; i++) {
|
|
304
|
+
this.showInlineError(this.errors[i]);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
FormValidator.prototype.showInlineError = function (error) {
|
|
309
|
+
const errorSpanId = `${error.fieldName}-error`;
|
|
310
|
+
const errorSpan = `<span class="govuk-error-message" id="${
|
|
311
|
+
errorSpanId
|
|
312
|
+
}">${this.escapeHtml(error.message)}</span>`;
|
|
313
|
+
const control = $(`#${error.fieldName}`);
|
|
314
|
+
const fieldContainer = control.parents('.govuk-form-group');
|
|
315
|
+
const label = fieldContainer.find('label');
|
|
316
|
+
const legend = fieldContainer.find('legend');
|
|
317
|
+
const fieldset = fieldContainer.find('fieldset');
|
|
318
|
+
fieldContainer.addClass('govuk-form-group--error');
|
|
319
|
+
if (legend.length) {
|
|
320
|
+
legend.after(errorSpan);
|
|
321
|
+
fieldContainer.attr('aria-invalid', 'true');
|
|
322
|
+
addAttributeValue(fieldset[0], 'aria-describedby', errorSpanId);
|
|
323
|
+
} else {
|
|
324
|
+
label.after(errorSpan);
|
|
325
|
+
control.attr('aria-invalid', 'true');
|
|
326
|
+
addAttributeValue(control[0], 'aria-describedby', errorSpanId);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
FormValidator.prototype.removeInlineErrors = function () {
|
|
331
|
+
for (let i = 0; i < this.errors.length; i++) {
|
|
332
|
+
this.removeInlineError(this.errors[i]);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
FormValidator.prototype.removeInlineError = function (error) {
|
|
337
|
+
const control = $(`#${error.fieldName}`);
|
|
338
|
+
const fieldContainer = control.parents('.govuk-form-group');
|
|
339
|
+
fieldContainer.find('.govuk-error-message').remove();
|
|
340
|
+
fieldContainer.removeClass('govuk-form-group--error');
|
|
341
|
+
fieldContainer.find('[aria-invalid]').attr('aria-invalid', 'false');
|
|
342
|
+
const errorSpanId = `${error.fieldName}-error`;
|
|
343
|
+
removeAttributeValue(
|
|
344
|
+
fieldContainer.find('[aria-describedby]')[0],
|
|
345
|
+
'aria-describedby',
|
|
346
|
+
errorSpanId
|
|
347
|
+
);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
FormValidator.prototype.addValidator = function (fieldName, rules) {
|
|
351
|
+
this.validators.push({
|
|
352
|
+
fieldName,
|
|
353
|
+
rules,
|
|
354
|
+
field: this.form.elements[fieldName]
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
FormValidator.prototype.validate = function () {
|
|
359
|
+
this.errors = [];
|
|
360
|
+
let validator = null;
|
|
361
|
+
let validatorReturnValue = true;
|
|
362
|
+
let i;
|
|
363
|
+
let j;
|
|
364
|
+
for (i = 0; i < this.validators.length; i++) {
|
|
365
|
+
validator = this.validators[i];
|
|
366
|
+
for (j = 0; j < validator.rules.length; j++) {
|
|
367
|
+
validatorReturnValue = validator.rules[j].method(
|
|
368
|
+
validator.field,
|
|
369
|
+
validator.rules[j].params
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
if (typeof validatorReturnValue === 'boolean' && !validatorReturnValue) {
|
|
373
|
+
this.errors.push({
|
|
374
|
+
fieldName: validator.fieldName,
|
|
375
|
+
message: validator.rules[j].message
|
|
376
|
+
});
|
|
377
|
+
break
|
|
378
|
+
} else if (typeof validatorReturnValue === 'string') {
|
|
379
|
+
this.errors.push({
|
|
380
|
+
fieldName: validatorReturnValue,
|
|
381
|
+
message: validator.rules[j].message
|
|
382
|
+
});
|
|
383
|
+
break
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return this.errors.length === 0
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
formValidator$1 = { FormValidator };
|
|
391
|
+
return formValidator$1;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
var formValidatorExports = requireFormValidator();
|
|
395
|
+
var formValidator = /*@__PURE__*/getDefaultExportFromCjs(formValidatorExports);
|
|
396
|
+
|
|
397
|
+
return formValidator;
|
|
398
|
+
|
|
399
|
+
}));
|