@planning-inspectorate/dynamic-forms 1.7.0 → 1.8.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/package.json
CHANGED
|
@@ -60,11 +60,13 @@
|
|
|
60
60
|
errorMessage: errors[inputField.fieldName] and {
|
|
61
61
|
text: errors[inputField.fieldName].msg
|
|
62
62
|
},
|
|
63
|
+
prefix: inputField.prefix,
|
|
64
|
+
suffix: inputField.suffix,
|
|
63
65
|
value: inputField.value,
|
|
64
66
|
hint: {
|
|
65
67
|
text: inputField.hint
|
|
66
68
|
},
|
|
67
|
-
classes: "govuk-input-!-width-three-quarters",
|
|
69
|
+
classes: inputField.classes or "govuk-input-!-width-three-quarters",
|
|
68
70
|
attributes: inputField.attributes
|
|
69
71
|
}) }}
|
|
70
72
|
{% endfor %}
|
|
@@ -10,6 +10,12 @@ import { nl2br } from '../../lib/utils.js';
|
|
|
10
10
|
* @typedef {import('../../validator/base-validator')} BaseValidator
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} Suffix
|
|
15
|
+
* @property {string} text
|
|
16
|
+
* @property {string} [classes] optional property, used to add classes to the suffix/prefix
|
|
17
|
+
*/
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* @typedef {Object} InputField
|
|
15
21
|
* @property {string} fieldName
|
|
@@ -18,6 +24,8 @@ import { nl2br } from '../../lib/utils.js';
|
|
|
18
24
|
* @property {string} [formatPrefix] optional property, used by formatAnswerForSummary (eg task list display), to prefix answer
|
|
19
25
|
* @property {function} [formatTextFunction] optional property, used to format the answer for display and value in question
|
|
20
26
|
* @property {Record<string, string>} [attributes] optional property, used to add html attributes to the field
|
|
27
|
+
* @property {Suffix} [suffix] optional property, used to add a suffix to the field
|
|
28
|
+
* @property {Suffix} [prefix] optional property, used to add a prefix to the field
|
|
21
29
|
*/
|
|
22
30
|
|
|
23
31
|
/**
|
|
@@ -14,9 +14,19 @@ export default class DateTimeValidator extends DateValidator {
|
|
|
14
14
|
* creates an instance of a DateTimeValidator
|
|
15
15
|
* @param {string} timeInputLabel - string representing the time fields as displayed on the UI as part of an error message
|
|
16
16
|
* @param {string} [dateInputLabel] - string representing the date fields as displayed on the UI as part of an error message
|
|
17
|
+
* @param {DateValidationSettings} [dateValidationSettings] - object containing rules to apply
|
|
18
|
+
* @param {Object} [dateErrorMessages] - object containing custom date error messages to show on validation failure
|
|
17
19
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
+
constructor(
|
|
21
|
+
timeInputLabel,
|
|
22
|
+
dateInputLabel = timeInputLabel,
|
|
23
|
+
dateValidationSettings = {
|
|
24
|
+
ensureFuture: false,
|
|
25
|
+
ensurePast: false
|
|
26
|
+
},
|
|
27
|
+
dateErrorMessages
|
|
28
|
+
) {
|
|
29
|
+
super(dateInputLabel, dateValidationSettings, dateErrorMessages);
|
|
20
30
|
this.timeInputLabel = timeInputLabel;
|
|
21
31
|
}
|
|
22
32
|
|
|
@@ -253,10 +253,35 @@ describe('./lib/forms/custom-components/date-time/date-time-validator.js', () =>
|
|
|
253
253
|
assert.strictEqual(errors[`${question.fieldName}_day`].msg, 'Enter Site visit');
|
|
254
254
|
assert.strictEqual(errors[`${question.fieldName}_hour`].msg, 'Enter the site visit time');
|
|
255
255
|
});
|
|
256
|
+
it('dateErrorMessages overrides errors returned by date validator', async () => {
|
|
257
|
+
const req = {
|
|
258
|
+
body: {
|
|
259
|
+
['date-time-question_day']: undefined,
|
|
260
|
+
['date-time-question_month']: undefined,
|
|
261
|
+
['date-time-question_year']: undefined,
|
|
262
|
+
['date-time-question_hour']: undefined,
|
|
263
|
+
['date-time-question_minutes']: undefined,
|
|
264
|
+
['date-time-question_period']: ''
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const errors = await _validationMappedErrors(req, question, 'Site visit', 'site visit date', {
|
|
269
|
+
emptyErrorMessage: 'Site visit date error override'
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
assert.strictEqual(Object.keys(errors).length, 6);
|
|
273
|
+
assert.strictEqual(errors[`${question.fieldName}_day`].msg, 'Site visit date error override');
|
|
274
|
+
assert.strictEqual(errors[`${question.fieldName}_hour`].msg, 'Enter the site visit time');
|
|
275
|
+
});
|
|
256
276
|
});
|
|
257
277
|
|
|
258
|
-
const _validationMappedErrors = async (req, question, inputLabel, dateInputLabel) => {
|
|
259
|
-
const dateTimeValidator = new DateTimeValidator(
|
|
278
|
+
const _validationMappedErrors = async (req, question, inputLabel, dateInputLabel, dateErrorMessages) => {
|
|
279
|
+
const dateTimeValidator = new DateTimeValidator(
|
|
280
|
+
inputLabel,
|
|
281
|
+
dateInputLabel,
|
|
282
|
+
{ ensureFuture: false, ensurePast: false },
|
|
283
|
+
dateErrorMessages
|
|
284
|
+
);
|
|
260
285
|
|
|
261
286
|
const validationRules = dateTimeValidator.validate(question);
|
|
262
287
|
|