@ukhomeoffice/cop-react-form-renderer 4.25.0 → 4.27.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 +4 -0
- package/dist/utils/Validate/additional/index.js +9 -3
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +22 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +38 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +35 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +55 -0
- package/package.json +1 -1
|
@@ -186,6 +186,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
186
186
|
window.onpopstate = function () {
|
|
187
187
|
var _formState$page;
|
|
188
188
|
|
|
189
|
+
if (document.location.hash) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
189
193
|
setGoingBack(true);
|
|
190
194
|
hooks.onGoingBack();
|
|
191
195
|
clearErrors();
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
|
|
9
|
+
|
|
8
10
|
var _mustBeAfter = _interopRequireDefault(require("./mustBeAfter"));
|
|
9
11
|
|
|
10
12
|
var _mustBeBefore = _interopRequireDefault(require("./mustBeBefore"));
|
|
@@ -25,12 +27,15 @@ var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
|
25
27
|
|
|
26
28
|
var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
|
|
27
29
|
|
|
28
|
-
var
|
|
30
|
+
var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
|
|
31
|
+
|
|
32
|
+
var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
|
|
29
33
|
|
|
30
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
35
|
|
|
32
36
|
// Local imports
|
|
33
37
|
var functions = {
|
|
38
|
+
conditionallyRequired: _conditionallyRequired.default,
|
|
34
39
|
mustBeAfter: _mustBeAfter.default,
|
|
35
40
|
mustBeBefore: _mustBeBefore.default,
|
|
36
41
|
mustBeEarlierDateTime: _mustBeEarlierDateTime.default,
|
|
@@ -38,10 +43,11 @@ var functions = {
|
|
|
38
43
|
mustBeInTheFuture: _mustBeInTheFuture.default,
|
|
39
44
|
mustBeLongerThan: _mustBeLongerThan.default,
|
|
40
45
|
mustBeShorterThan: _mustBeShorterThan.default,
|
|
41
|
-
conditionallyRequired: _conditionallyRequired.default,
|
|
42
46
|
mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
|
|
43
47
|
mustBeNumbersOnly: _mustBeNumbersOnly.default,
|
|
44
|
-
mustBeLessThan: _mustBeLessThan.default
|
|
48
|
+
mustBeLessThan: _mustBeLessThan.default,
|
|
49
|
+
mustHaveLessThanDecimalPlaces: _mustHaveLessThanDecimalPlaces.default,
|
|
50
|
+
mustSelectOnlyOne: _mustSelectOnlyOne.default
|
|
45
51
|
};
|
|
46
52
|
|
|
47
53
|
var additionalValidation = function additionalValidation(value, config, component) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} string - the string to check
|
|
10
|
+
* @param {number} config.maxDecimals - the maximum amount of decimal places to allow
|
|
11
|
+
* @returns true if string has less than maxDecimals decimal places else returns false
|
|
12
|
+
*/
|
|
13
|
+
var mustHaveLessThanDecimalPlaces = function mustHaveLessThanDecimalPlaces(string, config) {
|
|
14
|
+
if (!string || !string.includes('.')) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return string.split('.')[1].length < config.maxDecimals;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var _default = mustHaveLessThanDecimalPlaces;
|
|
22
|
+
exports.default = _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('utils', function () {
|
|
8
|
+
describe('Validate', function () {
|
|
9
|
+
describe('additional', function () {
|
|
10
|
+
describe('mustHaveLessThanDecimalPlaces', function () {
|
|
11
|
+
test('should return false given a number with more than the allowed number of decimal places', function () {
|
|
12
|
+
var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999.9999', {
|
|
13
|
+
maxDecimals: 3
|
|
14
|
+
});
|
|
15
|
+
expect(result).toEqual(false);
|
|
16
|
+
});
|
|
17
|
+
test('should return true given a number with less than the allowed number of decimal places', function () {
|
|
18
|
+
var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999.99', {
|
|
19
|
+
maxDecimals: 3
|
|
20
|
+
});
|
|
21
|
+
expect(result).toEqual(true);
|
|
22
|
+
});
|
|
23
|
+
test('should return true given a number with no decimal places', function () {
|
|
24
|
+
var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999', {
|
|
25
|
+
maxDecimals: 3
|
|
26
|
+
});
|
|
27
|
+
expect(result).toEqual(true);
|
|
28
|
+
});
|
|
29
|
+
test('should return true given nothing', function () {
|
|
30
|
+
var result = (0, _mustHaveLessThanDecimalPlaces.default)(undefined, {
|
|
31
|
+
maxDecimals: 3
|
|
32
|
+
});
|
|
33
|
+
expect(result).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Additional validator for the Container component type.
|
|
10
|
+
* @param {object} data the form data
|
|
11
|
+
* @param {object} component the container component
|
|
12
|
+
* @returns true if the user has only provided a value for one of the components in the container, otherwise false.
|
|
13
|
+
*/
|
|
14
|
+
var mustSelectOnlyOne = function mustSelectOnlyOne(data, _, component) {
|
|
15
|
+
var _component$components;
|
|
16
|
+
|
|
17
|
+
var valueCount = (_component$components = component.components) === null || _component$components === void 0 ? void 0 : _component$components.reduce(function (acc, inner) {
|
|
18
|
+
var _data$component$id;
|
|
19
|
+
|
|
20
|
+
if ((_data$component$id = data[component.id]) !== null && _data$component$id !== void 0 && _data$component$id[inner.id]) {
|
|
21
|
+
// Account for checkboxes that the user may have unselected
|
|
22
|
+
if (Array.isArray(data[component.id][inner.id]) && data[component.id][inner.id].length === 0) {
|
|
23
|
+
return acc;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return acc + 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return acc;
|
|
30
|
+
}, 0);
|
|
31
|
+
return valueCount < 2;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var _default = mustSelectOnlyOne;
|
|
35
|
+
exports.default = _default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
|
|
9
|
+
describe('utils', function () {
|
|
10
|
+
describe('Validate', function () {
|
|
11
|
+
describe('additional', function () {
|
|
12
|
+
describe('mustSelectOnlyOne', function () {
|
|
13
|
+
var CONTAINER_ID = 'containerId';
|
|
14
|
+
var COMPONENT = {
|
|
15
|
+
id: CONTAINER_ID,
|
|
16
|
+
type: 'container',
|
|
17
|
+
components: [{
|
|
18
|
+
id: 'alpha'
|
|
19
|
+
}, {
|
|
20
|
+
id: 'bravo'
|
|
21
|
+
}, {
|
|
22
|
+
id: 'charlie'
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
test('should return true if all components are empty', function () {
|
|
26
|
+
var DATA = {};
|
|
27
|
+
expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
|
|
28
|
+
});
|
|
29
|
+
test('should return true if one component has data', function () {
|
|
30
|
+
var DATA = _defineProperty({}, CONTAINER_ID, {
|
|
31
|
+
alpha: 'text'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
|
|
35
|
+
});
|
|
36
|
+
test('should return false if more than one component has data', function () {
|
|
37
|
+
var DATA = _defineProperty({}, CONTAINER_ID, {
|
|
38
|
+
alpha: 'text',
|
|
39
|
+
bravo: 'test'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(false);
|
|
43
|
+
});
|
|
44
|
+
test('should return true if more than one component has data but one is an empty array', function () {
|
|
45
|
+
var DATA = _defineProperty({}, CONTAINER_ID, {
|
|
46
|
+
alpha: 'text',
|
|
47
|
+
bravo: []
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|