@ukhomeoffice/cop-react-form-renderer 4.58.0 → 4.60.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/dist/components/FormRenderer/FormRenderer.js +11 -11
- package/dist/context/HooksContext/HooksContext.js +2 -4
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +10 -0
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -6
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/package.json +1 -1
|
@@ -254,8 +254,11 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
254
254
|
}, [pages, hub, pageId, setFormState, type, goingBack, data, formState.page]); // Call the onFormLoad hook just when this component first renders.
|
|
255
255
|
|
|
256
256
|
(0, _react.useEffect)(function () {
|
|
257
|
-
setPagePoint(undefined);
|
|
258
|
-
|
|
257
|
+
setPagePoint(undefined); // In case of refresh the current task needs to be reset
|
|
258
|
+
|
|
259
|
+
hooks.onFormLoad(function (currentTask) {
|
|
260
|
+
return setCurrentTask(currentTask);
|
|
261
|
+
});
|
|
259
262
|
}, [hooks]);
|
|
260
263
|
(0, _react.useEffect)(function () {
|
|
261
264
|
setHubDetails(_hub);
|
|
@@ -357,9 +360,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
357
360
|
break;
|
|
358
361
|
|
|
359
362
|
case _models.PageAction.TYPES.SAVE_AND_NAVIGATE:
|
|
360
|
-
var state = {
|
|
361
|
-
'fullPages': currentTask.fullPages
|
|
362
|
-
};
|
|
363
|
+
var state = _objectSpread({}, currentTask);
|
|
363
364
|
|
|
364
365
|
pageUpdate = function pageUpdate() {
|
|
365
366
|
return _handlers.default.navigate(action, pageId, onPageChange, state);
|
|
@@ -490,6 +491,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
490
491
|
});
|
|
491
492
|
setCurrentTask(currentTask);
|
|
492
493
|
|
|
494
|
+
var state = _objectSpread({}, currentTask);
|
|
495
|
+
|
|
493
496
|
if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
|
|
494
497
|
if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
|
|
495
498
|
var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
@@ -497,19 +500,16 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
497
500
|
} else if (currentTask.customCYA) {
|
|
498
501
|
onPageChange(currentTask.customCYA);
|
|
499
502
|
} else {
|
|
500
|
-
onPageChange(_models.FormPages.CYA);
|
|
503
|
+
onPageChange(_models.FormPages.CYA, state);
|
|
501
504
|
}
|
|
502
505
|
} else if (currentTask.state === _models.TaskStates.TYPES.IN_PROGRESS) {
|
|
503
506
|
var _currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
504
|
-
var state = {
|
|
505
|
-
'fullPages': currentTask.fullPages
|
|
506
|
-
};
|
|
507
507
|
onPageChange(_currentPage || currentTask.pages[0], state);
|
|
508
508
|
} else if (currentTask.firstPage) {
|
|
509
509
|
var _currentPage2 = currentTask.firstPage;
|
|
510
|
-
onPageChange(_currentPage2 || currentTask.pages[0]);
|
|
510
|
+
onPageChange(_currentPage2 || currentTask.pages[0], state);
|
|
511
511
|
} else {
|
|
512
|
-
onPageChange(currentTask.pages[0]);
|
|
512
|
+
onPageChange(currentTask.pages[0], state);
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
}; // Handle actions from "Check your answers".
|
|
@@ -32,11 +32,9 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
32
32
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
33
33
|
|
|
34
34
|
var DEFAULT_HOOKS = {
|
|
35
|
-
onChange: function onChange(data) {
|
|
36
|
-
return data;
|
|
37
|
-
},
|
|
35
|
+
onChange: function onChange(data) {},
|
|
38
36
|
onFormComplete: function onFormComplete() {},
|
|
39
|
-
onFormLoad: function onFormLoad() {},
|
|
37
|
+
onFormLoad: function onFormLoad(setCurrentTask) {},
|
|
40
38
|
onGetComponent: function onGetComponent(config, wrap) {
|
|
41
39
|
return null;
|
|
42
40
|
},
|
|
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {number} config.value - the
|
|
11
|
-
* @returns true if
|
|
9
|
+
* @param {*} value - the value to check.
|
|
10
|
+
* @param {number} config.value - the value must be greater than config.value.
|
|
11
|
+
* @returns true if value is greater than config.value, false if not.
|
|
12
12
|
*/
|
|
13
|
-
var mustBeGreaterThan = function mustBeGreaterThan(
|
|
14
|
-
if (!
|
|
13
|
+
var mustBeGreaterThan = function mustBeGreaterThan(value, config) {
|
|
14
|
+
if (!value) {
|
|
15
15
|
// null, undefined and empty strings should be picked up by the required flag
|
|
16
16
|
// and not considered here as they would be valid for optional fields.
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
21
|
+
return parseFloat(finalValue) > config.value;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
var _default = mustBeGreaterThan;
|
|
@@ -24,6 +24,16 @@ describe('utils', function () {
|
|
|
24
24
|
});
|
|
25
25
|
expect(result2).toBeFalsy();
|
|
26
26
|
});
|
|
27
|
+
test('should correctly handle numbers with commas in', function () {
|
|
28
|
+
var result1 = (0, _mustBeGreaterThan.default)('999,999,999.99', {
|
|
29
|
+
value: 1000000000
|
|
30
|
+
});
|
|
31
|
+
expect(result1).toEqual(false);
|
|
32
|
+
var result2 = (0, _mustBeGreaterThan.default)('1,000,000,123', {
|
|
33
|
+
value: 1000000000
|
|
34
|
+
});
|
|
35
|
+
expect(result2).toEqual(true);
|
|
36
|
+
});
|
|
27
37
|
test('should return true when string is undefined', function () {
|
|
28
38
|
var result = (0, _mustBeGreaterThan.default)(undefined, {
|
|
29
39
|
value: 10
|
|
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {number} config.value - the
|
|
11
|
-
* @returns true if
|
|
9
|
+
* @param {*} value - the value to check.
|
|
10
|
+
* @param {number} config.value - the value must be equal or less than config.value.
|
|
11
|
+
* @returns true if value is equal to or less then config.value, false if not.
|
|
12
12
|
*/
|
|
13
|
-
var mustBeLessThan = function mustBeLessThan(
|
|
14
|
-
if (!
|
|
13
|
+
var mustBeLessThan = function mustBeLessThan(value, config) {
|
|
14
|
+
if (!value) {
|
|
15
15
|
// null, undefined and empty strings should be picked up by the required flag
|
|
16
16
|
// and not considered here as they would be valid for optional fields.
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
21
|
+
return parseFloat(finalValue) < config.value;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
var _default = mustBeLessThan;
|
|
@@ -7,7 +7,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
7
7
|
describe('utils', function () {
|
|
8
8
|
describe('Validate', function () {
|
|
9
9
|
describe('additional', function () {
|
|
10
|
-
describe('
|
|
10
|
+
describe('mustBeLessThan', function () {
|
|
11
11
|
test('should return true given a number equal to or less than 1000000000', function () {
|
|
12
12
|
var result = (0, _mustBeLessThan.default)(999999999.999, {
|
|
13
13
|
value: 1000000000
|
|
@@ -20,6 +20,16 @@ describe('utils', function () {
|
|
|
20
20
|
});
|
|
21
21
|
expect(result).toBeFalsy();
|
|
22
22
|
});
|
|
23
|
+
test('should correctly handle numbers with commas in', function () {
|
|
24
|
+
var result1 = (0, _mustBeLessThan.default)('999,999,999.99', {
|
|
25
|
+
value: 1000000000
|
|
26
|
+
});
|
|
27
|
+
expect(result1).toEqual(true);
|
|
28
|
+
var result2 = (0, _mustBeLessThan.default)('1,000,000,123', {
|
|
29
|
+
value: 1000000000
|
|
30
|
+
});
|
|
31
|
+
expect(result2).toEqual(false);
|
|
32
|
+
});
|
|
23
33
|
test('should return true when string is undefined', function () {
|
|
24
34
|
var result = (0, _mustBeLessThan.default)(undefined, {
|
|
25
35
|
value: 3
|
|
@@ -6,18 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Checks if a string contains only numberical characters.
|
|
10
|
+
* An optional flag in config can be used to allow commas.
|
|
11
|
+
* @param {*} value The value to check for only numerical characters.
|
|
12
|
+
* @param {object} config The config of the validation check.
|
|
13
|
+
* @returns true if value passes the regex, false if not.
|
|
10
14
|
*/
|
|
11
|
-
var mustBeNumbersOnly = function mustBeNumbersOnly(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!number) {
|
|
15
|
+
var mustBeNumbersOnly = function mustBeNumbersOnly(value, config) {
|
|
16
|
+
if (!value) {
|
|
15
17
|
// null, undefined and empty numbers should be picked up by the required flag
|
|
16
18
|
// and not considered here as they would be valid for optional fields.
|
|
17
19
|
return true;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
var regex = config !== null && config !== void 0 && config.allowCommas ? /^[0-9,]*\.?[0-9]*$/ : /^[0-9]*\.?[0-9]*$/;
|
|
23
|
+
return regex.test(value);
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
var _default = mustBeNumbersOnly;
|
|
@@ -16,10 +16,18 @@ describe('utils', function () {
|
|
|
16
16
|
var result = (0, _mustBeNumbersOnly.default)('123456.123');
|
|
17
17
|
expect(result).toEqual(true);
|
|
18
18
|
});
|
|
19
|
-
test('should return false if given number contains
|
|
20
|
-
var
|
|
19
|
+
test('should return false if given number contains commas and config does not allow them', function () {
|
|
20
|
+
var CONFIG = {};
|
|
21
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
21
22
|
expect(result).toEqual(false);
|
|
22
23
|
});
|
|
24
|
+
test('should return true if given number contains commas and config allows them', function () {
|
|
25
|
+
var CONFIG = {
|
|
26
|
+
allowCommas: true
|
|
27
|
+
};
|
|
28
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
29
|
+
expect(result).toEqual(true);
|
|
30
|
+
});
|
|
23
31
|
test('should return true when string is undefined', function () {
|
|
24
32
|
var result = (0, _mustBeNumbersOnly.default)(undefined);
|
|
25
33
|
expect(result).toEqual(true);
|