@sumaris-net/ngx-components 0.27.15 → 0.27.16
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/bundles/sumaris-net.ngx-components.umd.js +23 -12
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/src/app/shared/validator/validators.js +25 -14
- package/fesm2015/sumaris-net.ngx-components.js +23 -12
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/shared/validator/validators.d.ts +2 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -2926,6 +2926,18 @@
|
|
|
2926
2926
|
var SharedValidators = /** @class */ (function () {
|
|
2927
2927
|
function SharedValidators() {
|
|
2928
2928
|
}
|
|
2929
|
+
SharedValidators.getDoubleRegexp = function (maxDecimals) {
|
|
2930
|
+
if (isNil(maxDecimals))
|
|
2931
|
+
return this._REGEXP_CACHE.DOUBLE_BY_MAX_DECIMALS.NO_LIMIT;
|
|
2932
|
+
if (maxDecimals < 0)
|
|
2933
|
+
throw new Error("Invalid maxDecimals value: " + maxDecimals);
|
|
2934
|
+
var regexp = this._REGEXP_CACHE.DOUBLE_BY_MAX_DECIMALS[maxDecimals];
|
|
2935
|
+
if (regexp)
|
|
2936
|
+
return regexp;
|
|
2937
|
+
// New regexp: add it to cache
|
|
2938
|
+
this._REGEXP_CACHE.DOUBLE_BY_MAX_DECIMALS[maxDecimals] = new RegExp("^[-]?[0-9]+([.,][0-9]{1," + maxDecimals + "})?$");
|
|
2939
|
+
return this._REGEXP_CACHE.DOUBLE_BY_MAX_DECIMALS[maxDecimals];
|
|
2940
|
+
};
|
|
2929
2941
|
SharedValidators.validDate = function (control) {
|
|
2930
2942
|
var value = control.value;
|
|
2931
2943
|
var date = !value || moment$4.isMoment(value) ? value : moment$4(control.value, DATE_ISO_PATTERN);
|
|
@@ -2985,24 +2997,15 @@
|
|
|
2985
2997
|
return null;
|
|
2986
2998
|
};
|
|
2987
2999
|
SharedValidators.double = function (opts) {
|
|
2988
|
-
var
|
|
2989
|
-
if (opts && isNotNil(opts.maxDecimals)) {
|
|
2990
|
-
if (opts.maxDecimals < 0)
|
|
2991
|
-
throw new Error("Invalid maxDecimals value: " + opts.maxDecimals);
|
|
2992
|
-
regexpStr = opts.maxDecimals > 1 ? "^[-]?[0-9]+([.,][0-9]{1," + opts.maxDecimals + "})?$" : '^[-]?[0-9]+([.,][0-9])?$';
|
|
2993
|
-
}
|
|
2994
|
-
else {
|
|
2995
|
-
regexpStr = '^[-]?[0-9]+([.,][0-9]*)?$';
|
|
2996
|
-
}
|
|
2997
|
-
var regexp = new RegExp(regexpStr);
|
|
3000
|
+
var regexp = this.getDoubleRegexp(opts === null || opts === void 0 ? void 0 : opts.maxDecimals);
|
|
2998
3001
|
return function (control) {
|
|
2999
3002
|
var value = control.value;
|
|
3000
3003
|
if (Number.isNaN(value)) {
|
|
3001
3004
|
//console.log("WARN: Getting a NaN value !");
|
|
3002
|
-
|
|
3005
|
+
return null;
|
|
3003
3006
|
}
|
|
3004
3007
|
if (isNotNil(value) && value !== '' && !regexp.test(value)) {
|
|
3005
|
-
return { maxDecimals:
|
|
3008
|
+
return { maxDecimals: { maxDecimals: opts === null || opts === void 0 ? void 0 : opts.maxDecimals } };
|
|
3006
3009
|
}
|
|
3007
3010
|
return null;
|
|
3008
3011
|
};
|
|
@@ -3095,6 +3098,14 @@
|
|
|
3095
3098
|
};
|
|
3096
3099
|
return SharedValidators;
|
|
3097
3100
|
}());
|
|
3101
|
+
SharedValidators._REGEXP_CACHE = {
|
|
3102
|
+
DOUBLE_BY_MAX_DECIMALS: {
|
|
3103
|
+
NO_LIMIT: /^[-]?[0-9]+([.,][0-9]*)?$/,
|
|
3104
|
+
1: /^[-]?[0-9]+([.,][0-9])?$/,
|
|
3105
|
+
2: /^[-]?[0-9]+([.,][0-9]{1,2})?$/,
|
|
3106
|
+
3: /^[-]?[0-9]+([.,][0-9]{1,2})?$/,
|
|
3107
|
+
}
|
|
3108
|
+
};
|
|
3098
3109
|
SharedValidators.I18N_ERROR_KEYS = {
|
|
3099
3110
|
required: 'ERROR.FIELD_REQUIRED',
|
|
3100
3111
|
min: 'ERROR.FIELD_MIN',
|