@ukhomeoffice/cop-react-form-renderer 3.33.0 → 3.35.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/hooks/useRefData.js +1 -1
- package/dist/utils/Validate/additional/index.js +7 -1
- package/dist/utils/Validate/additional/mustBeLessThan.js +24 -0
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +44 -0
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +24 -0
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +38 -0
- package/package.json +1 -1
package/dist/hooks/useRefData.js
CHANGED
|
@@ -82,7 +82,7 @@ var useRefData = function useRefData(component, formData) {
|
|
|
82
82
|
setStatus(STATUS_COMPLETE);
|
|
83
83
|
} else if (_status === _useGetRequest2.STATUS_FETCHED) {
|
|
84
84
|
if (_data) {
|
|
85
|
-
setData(_Data.default.refData.toOptions(_data.data, component.item));
|
|
85
|
+
setData(_Data.default.refData.toOptions(_data.data || _data, component.item));
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
setStatus(STATUS_COMPLETE);
|
|
@@ -19,6 +19,10 @@ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
|
|
|
19
19
|
|
|
20
20
|
var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
|
|
21
21
|
|
|
22
|
+
var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
23
|
+
|
|
24
|
+
var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
|
|
25
|
+
|
|
22
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
27
|
|
|
24
28
|
// Local imports
|
|
@@ -29,7 +33,9 @@ var functions = {
|
|
|
29
33
|
mustBeInTheFuture: _mustBeInTheFuture.default,
|
|
30
34
|
mustBeLongerThan: _mustBeLongerThan.default,
|
|
31
35
|
mustBeShorterThan: _mustBeShorterThan.default,
|
|
32
|
-
mustEnterAtLeastOne: _mustEnterAtLeastOne.default
|
|
36
|
+
mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
|
|
37
|
+
mustBeNumbersOnly: _mustBeNumbersOnly.default,
|
|
38
|
+
mustBeLessThan: _mustBeLessThan.default
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
var additionalValidation = function additionalValidation(value, config, component) {
|
|
@@ -0,0 +1,24 @@
|
|
|
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 value.
|
|
10
|
+
* @param {number} config.value - the string.value must be equal or less than config.value.
|
|
11
|
+
* @returns true if sting value is equal to or less then config.value, false if not.
|
|
12
|
+
*/
|
|
13
|
+
var mustBeLessThan = function mustBeLessThan(string, config) {
|
|
14
|
+
if (!string) {
|
|
15
|
+
// null, undefined and empty strings should be picked up by the required flag
|
|
16
|
+
// and not considered here as they would be valid for optional fields.
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return string < config.value;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var _default = mustBeLessThan;
|
|
24
|
+
exports.default = _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
|
|
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('mustBeShorterThan', function () {
|
|
11
|
+
test('should return true given a number equal to or less than 1000000000', function () {
|
|
12
|
+
var result = (0, _mustBeLessThan.default)(999999999.999, {
|
|
13
|
+
value: 1000000000
|
|
14
|
+
});
|
|
15
|
+
expect(result).toEqual(true);
|
|
16
|
+
});
|
|
17
|
+
test('should return false if provided value greater than 1000000000', function () {
|
|
18
|
+
var result = (0, _mustBeLessThan.default)('1000000000.9', {
|
|
19
|
+
value: 1000000000
|
|
20
|
+
});
|
|
21
|
+
expect(result).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
test('should return true when string is undefined', function () {
|
|
24
|
+
var result = (0, _mustBeLessThan.default)(undefined, {
|
|
25
|
+
value: 3
|
|
26
|
+
});
|
|
27
|
+
expect(result).toEqual(true);
|
|
28
|
+
});
|
|
29
|
+
test('should return true when string is empty', function () {
|
|
30
|
+
var result = (0, _mustBeLessThan.default)('', {
|
|
31
|
+
value: 3
|
|
32
|
+
});
|
|
33
|
+
expect(result).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
test('should return true when string is null', function () {
|
|
36
|
+
var result = (0, _mustBeLessThan.default)(null, {
|
|
37
|
+
value: 3
|
|
38
|
+
});
|
|
39
|
+
expect(result).toEqual(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @returns true if number pass the regex, false if not.
|
|
10
|
+
*/
|
|
11
|
+
var mustBeNumbersOnly = function mustBeNumbersOnly(number) {
|
|
12
|
+
var numbersOnlyRegex = /^[0-9]*\.?[0-9]*$/;
|
|
13
|
+
|
|
14
|
+
if (!number) {
|
|
15
|
+
// null, undefined and empty numbers should be picked up by the required flag
|
|
16
|
+
// and not considered here as they would be valid for optional fields.
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return numbersOnlyRegex.test(number);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var _default = mustBeNumbersOnly;
|
|
24
|
+
exports.default = _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
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('mustBeNumbersOnly', function () {
|
|
11
|
+
test('should return true given a string is number', function () {
|
|
12
|
+
var result = (0, _mustBeNumbersOnly.default)('349732');
|
|
13
|
+
expect(result).toEqual(true);
|
|
14
|
+
});
|
|
15
|
+
test('should return true given a string is numbers contains desimile', function () {
|
|
16
|
+
var result = (0, _mustBeNumbersOnly.default)('123456.123');
|
|
17
|
+
expect(result).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
test('should return false if given number contains letters', function () {
|
|
20
|
+
var result = (0, _mustBeNumbersOnly.default)('123124Hello');
|
|
21
|
+
expect(result).toEqual(false);
|
|
22
|
+
});
|
|
23
|
+
test('should return true when string is undefined', function () {
|
|
24
|
+
var result = (0, _mustBeNumbersOnly.default)(undefined);
|
|
25
|
+
expect(result).toEqual(true);
|
|
26
|
+
});
|
|
27
|
+
test('should return true when string is empty', function () {
|
|
28
|
+
var result = (0, _mustBeNumbersOnly.default)('');
|
|
29
|
+
expect(result).toEqual(true);
|
|
30
|
+
});
|
|
31
|
+
test('should return true when string is null', function () {
|
|
32
|
+
var result = (0, _mustBeNumbersOnly.default)(null);
|
|
33
|
+
expect(result).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|