@dhis2/ui-forms 8.4.4 → 8.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,10 +9,10 @@ describe('validator: integer', () => {
9
9
  describe('allows integers and string representations of integers', () => {
10
10
  (0, _index.testValidatorValues)(_integer.integer, undefined, [-2, 0, 2, 10000, '-2', '0', '2', '10000', 12e4]);
11
11
  });
12
- describe('rejects other data types', () => {
13
- (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, ['text', true, {}, [], () => {}]);
12
+ describe('rejects other data types and leading zeros', () => {
13
+ (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, ['text', '014', true, {}, [], () => {}]);
14
14
  });
15
15
  describe('rejects floats and string representations of floats', () => {
16
- (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, [0.23456, 5.987, 1e-12, '0.23456', '5.987', '1e-12']);
16
+ (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, [0.23456, 5.987, 1e-12, '4.0', '4.000', '4,0', '0.23456', '5.987', '1e-12']);
17
17
  });
18
18
  });
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toNumber = exports.requiredArgumentErrorMessage = exports.requireArgument = exports.isString = exports.isNumeric = exports.isNumber = exports.isInteger = exports.isInRange = exports.isEmpty = void 0;
6
+ exports.toNumber = exports.requiredArgumentErrorMessage = exports.requireArgument = exports.isString = exports.isNumeric = exports.isNumber = exports.isInRange = exports.isEmpty = void 0;
7
7
 
8
8
  const isEmpty = value => typeof value === 'undefined' || value === null || value === '';
9
9
 
@@ -13,10 +13,6 @@ const isString = value => typeof value === 'string';
13
13
 
14
14
  exports.isString = isString;
15
15
 
16
- const isInteger = value => Number.isSafeInteger(value);
17
-
18
- exports.isInteger = isInteger;
19
-
20
16
  const isNumber = value => typeof value === 'number';
21
17
 
22
18
  exports.isNumber = isNumber;
@@ -11,10 +11,13 @@ var _index2 = require("./helpers/index.js");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const invalidIntegerMessage = _index.default.t('Please provide a round number without decimals');
14
+ const invalidIntegerMessage = _index.default.t('Please provide a round number without decimals'); // Regex accepts only digits (no decimals even if it is trailing like 4.0)
15
+ // it also rejects a leading 0 (i.e 04) as this is rejected by backend
16
+
15
17
 
16
18
  exports.invalidIntegerMessage = invalidIntegerMessage;
19
+ const INTEGER_PATTERN = /^(-?[1-9]\d*|0)$/;
17
20
 
18
- const integer = value => (0, _index2.isEmpty)(value) || (0, _index2.isNumeric)(value) && (0, _index2.isInteger)((0, _index2.toNumber)(value)) ? undefined : invalidIntegerMessage;
21
+ const integer = value => (0, _index2.isEmpty)(value) || INTEGER_PATTERN.test(value) && (0, _index2.isNumeric)(value) && Number.isSafeInteger((0, _index2.toNumber)(value)) ? undefined : invalidIntegerMessage;
19
22
 
20
23
  exports.integer = integer;
@@ -5,10 +5,10 @@ describe('validator: integer', () => {
5
5
  describe('allows integers and string representations of integers', () => {
6
6
  testValidatorValues(integer, undefined, [-2, 0, 2, 10000, '-2', '0', '2', '10000', 12e4]);
7
7
  });
8
- describe('rejects other data types', () => {
9
- testValidatorValues(integer, invalidIntegerMessage, ['text', true, {}, [], () => {}]);
8
+ describe('rejects other data types and leading zeros', () => {
9
+ testValidatorValues(integer, invalidIntegerMessage, ['text', '014', true, {}, [], () => {}]);
10
10
  });
11
11
  describe('rejects floats and string representations of floats', () => {
12
- testValidatorValues(integer, invalidIntegerMessage, [0.23456, 5.987, 1e-12, '0.23456', '5.987', '1e-12']);
12
+ testValidatorValues(integer, invalidIntegerMessage, [0.23456, 5.987, 1e-12, '4.0', '4.000', '4,0', '0.23456', '5.987', '1e-12']);
13
13
  });
14
14
  });
@@ -1,6 +1,5 @@
1
1
  export const isEmpty = value => typeof value === 'undefined' || value === null || value === '';
2
2
  export const isString = value => typeof value === 'string';
3
- export const isInteger = value => Number.isSafeInteger(value);
4
3
  export const isNumber = value => typeof value === 'number';
5
4
  export const isNumeric = value => (isString(value) || isNumber(value)) && !isNaN(value);
6
5
  export const isInRange = (lowerBound, upperBound, value) => value >= lowerBound && value <= upperBound;
@@ -1,7 +1,10 @@
1
1
  import i18n from '../locales/index.js';
2
- import { isEmpty, isInteger, isNumeric, toNumber } from './helpers/index.js';
3
- const invalidIntegerMessage = i18n.t('Please provide a round number without decimals');
2
+ import { isEmpty, isNumeric, toNumber } from './helpers/index.js';
3
+ const invalidIntegerMessage = i18n.t('Please provide a round number without decimals'); // Regex accepts only digits (no decimals even if it is trailing like 4.0)
4
+ // it also rejects a leading 0 (i.e 04) as this is rejected by backend
4
5
 
5
- const integer = value => isEmpty(value) || isNumeric(value) && isInteger(toNumber(value)) ? undefined : invalidIntegerMessage;
6
+ const INTEGER_PATTERN = /^(-?[1-9]\d*|0)$/;
7
+
8
+ const integer = value => isEmpty(value) || INTEGER_PATTERN.test(value) && isNumeric(value) && Number.isSafeInteger(toNumber(value)) ? undefined : invalidIntegerMessage;
6
9
 
7
10
  export { integer, invalidIntegerMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/ui-forms",
3
- "version": "8.4.4",
3
+ "version": "8.4.7",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "sideEffects": [
@@ -34,15 +34,15 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.1.2",
37
- "@dhis2-ui/button": "8.4.4",
38
- "@dhis2-ui/checkbox": "8.4.4",
39
- "@dhis2-ui/field": "8.4.4",
40
- "@dhis2-ui/file-input": "8.4.4",
41
- "@dhis2-ui/input": "8.4.4",
42
- "@dhis2-ui/radio": "8.4.4",
43
- "@dhis2-ui/select": "8.4.4",
44
- "@dhis2-ui/switch": "8.4.4",
45
- "@dhis2-ui/text-area": "8.4.4",
37
+ "@dhis2-ui/button": "8.4.7",
38
+ "@dhis2-ui/checkbox": "8.4.7",
39
+ "@dhis2-ui/field": "8.4.7",
40
+ "@dhis2-ui/file-input": "8.4.7",
41
+ "@dhis2-ui/input": "8.4.7",
42
+ "@dhis2-ui/radio": "8.4.7",
43
+ "@dhis2-ui/select": "8.4.7",
44
+ "@dhis2-ui/switch": "8.4.7",
45
+ "@dhis2-ui/text-area": "8.4.7",
46
46
  "classnames": "^2.3.1",
47
47
  "final-form": "^4.20.2",
48
48
  "prop-types": "^15.7.2",