@sumaris-net/ngx-components 2.4.77 → 2.4.78
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/esm2020/src/app/shared/validator/validators.mjs +18 -7
- package/fesm2015/sumaris-net.ngx-components.mjs +17 -6
- package/fesm2015/sumaris-net.ngx-components.mjs.map +1 -1
- package/fesm2020/sumaris-net.ngx-components.mjs +17 -6
- package/fesm2020/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/shared/validator/validators.d.ts +1 -1
|
@@ -3671,7 +3671,8 @@ class SharedValidators {
|
|
|
3671
3671
|
return (control) => {
|
|
3672
3672
|
let value = control.value;
|
|
3673
3673
|
if (Number.isNaN(value)) {
|
|
3674
|
-
//
|
|
3674
|
+
// DEBUG
|
|
3675
|
+
//console.debug("WARN: Getting a NaN value (decimal was expected) !");
|
|
3675
3676
|
return null;
|
|
3676
3677
|
}
|
|
3677
3678
|
if (isNotNil(value) && value !== '' && !regexp.test(value)) {
|
|
@@ -3681,18 +3682,28 @@ class SharedValidators {
|
|
|
3681
3682
|
};
|
|
3682
3683
|
}
|
|
3683
3684
|
/**
|
|
3684
|
-
* Check precision. e.g. if precision=0.5 then value=0.6 is invalid
|
|
3685
|
+
* Check precision. e.g. if precision=0.5 then value=0.6 is invalid, but 1.5 is valid
|
|
3685
3686
|
* @param precision
|
|
3686
3687
|
*/
|
|
3687
3688
|
static precision(precision) {
|
|
3688
|
-
if (precision
|
|
3689
|
-
throw new Error('
|
|
3689
|
+
if (isNil(precision))
|
|
3690
|
+
throw new Error('Required a not nil precision');
|
|
3691
|
+
// WARN: we should define a multiplier, because modulo in javascript will only work on integer
|
|
3692
|
+
// (e.g. "7 % 0.1" in javascript will NOT return zero (but 0.09999999999999962)
|
|
3693
|
+
const precisionNbDecimals = (precision.toString().split('.')[1] || '').length;
|
|
3694
|
+
const multiplier = Math.pow(10, precisionNbDecimals);
|
|
3695
|
+
const multipliedPrecision = Math.round(multiplier * precision);
|
|
3696
|
+
// The validator function
|
|
3690
3697
|
return (control) => {
|
|
3691
3698
|
const value = control.value;
|
|
3692
|
-
if (
|
|
3699
|
+
if (isNilOrBlank(value) || Number.isNaN(value)) {
|
|
3693
3700
|
return null;
|
|
3694
3701
|
}
|
|
3695
|
-
|
|
3702
|
+
// WARN: Convert value into integer, before applying modulo operator
|
|
3703
|
+
const mod = Math.round(+value * multiplier) % multipliedPrecision;
|
|
3704
|
+
if (mod !== 0) {
|
|
3705
|
+
// DEBUG
|
|
3706
|
+
//console.debug(`WARN Getting a ${value} with an invalid precision (expected precision is: ${precision})`);
|
|
3696
3707
|
return { precision: { precision } };
|
|
3697
3708
|
}
|
|
3698
3709
|
return null;
|