tuain-ng-forms-lib 0.12.20 → 0.12.21
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/tuain-ng-forms-lib.umd.js +128 -17
- package/bundles/tuain-ng-forms-lib.umd.js.map +1 -1
- package/esm2015/lib/classes/forms/field.js +85 -12
- package/esm2015/lib/classes/forms/form.js +9 -1
- package/esm2015/lib/components/forms/basic-form.js +16 -6
- package/fesm2015/tuain-ng-forms-lib.js +107 -16
- package/fesm2015/tuain-ng-forms-lib.js.map +1 -1
- package/lib/classes/forms/field.d.ts +26 -3
- package/lib/classes/forms/form.d.ts +2 -0
- package/lib/components/forms/basic-form.d.ts +4 -2
- package/package.json +1 -1
- package/tuain-ng-forms-lib.metadata.json +1 -1
|
@@ -1937,13 +1937,40 @@
|
|
|
1937
1937
|
var FIELD_TOOLTIP = 'tooltipText';
|
|
1938
1938
|
var FIELD_INFO = 'info';
|
|
1939
1939
|
var FIELD_EDITABLE = 'editable';
|
|
1940
|
+
var EMAIL_FORMAT = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$';
|
|
1941
|
+
// Norbey ".+@([\da-z\.-]+)\.([a-z\.]{2,6})"
|
|
1942
|
+
var FIELD_TYPES = {
|
|
1943
|
+
array: 'ARRAY',
|
|
1944
|
+
check: 'CHECK',
|
|
1945
|
+
date: 'DATE',
|
|
1946
|
+
daterange: 'DATERANGE',
|
|
1947
|
+
time: 'TIME',
|
|
1948
|
+
timerange: 'TIMERANGE',
|
|
1949
|
+
map: 'MAP',
|
|
1950
|
+
number: 'NUMBER',
|
|
1951
|
+
decimal: 'DECIMAL',
|
|
1952
|
+
currency: 'CURRENCY',
|
|
1953
|
+
select: 'SELECT',
|
|
1954
|
+
typeahead: 'TYPEAHEAD',
|
|
1955
|
+
text: 'TEXT',
|
|
1956
|
+
password: 'PASSWORD',
|
|
1957
|
+
label: 'LABEL',
|
|
1958
|
+
html: 'HTML',
|
|
1959
|
+
title: 'TITLE',
|
|
1960
|
+
message: 'MESSAGE',
|
|
1961
|
+
link: 'LINK',
|
|
1962
|
+
warning: 'WARNING',
|
|
1963
|
+
avatar: 'AVATAR',
|
|
1964
|
+
email: 'EMAIL',
|
|
1965
|
+
phone: 'PHONE',
|
|
1966
|
+
};
|
|
1940
1967
|
var STD_MAX_LENGTH = 50;
|
|
1941
1968
|
var BIG_MAX_LENGTH = 500;
|
|
1942
1969
|
var FieldDescriptor = /** @class */ (function (_super) {
|
|
1943
1970
|
__extends(FieldDescriptor, _super);
|
|
1944
1971
|
function FieldDescriptor(inputFieldReceived) {
|
|
1945
1972
|
var _this = this;
|
|
1946
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1973
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1947
1974
|
_this = _super.call(this, inputFieldReceived) || this;
|
|
1948
1975
|
_this._editionFinish = new rxjs.Subject();
|
|
1949
1976
|
_this._editionPartial = new rxjs.Subject();
|
|
@@ -1970,9 +1997,12 @@
|
|
|
1970
1997
|
_this.defaultEditable = _this.enabled;
|
|
1971
1998
|
_this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
|
|
1972
1999
|
_this.errorMessage = fieldReceived.errorMessage || '';
|
|
1973
|
-
_this.errorCode = fieldReceived.errorCode
|
|
1974
|
-
_this.outputOnly = (
|
|
2000
|
+
_this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
|
|
2001
|
+
_this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
|
|
1975
2002
|
_this.setFieldOptions(fieldReceived.fieldOptions);
|
|
2003
|
+
_this._intrinsicErrorMessage = (_this.fieldType === FIELD_TYPES.email)
|
|
2004
|
+
? "El valor de " + _this.fieldTitle + " no corresponde a un correo v\u00E1lido"
|
|
2005
|
+
: "El valor de " + _this.fieldTitle + " no se ajusta al formato establecido";
|
|
1976
2006
|
return _this;
|
|
1977
2007
|
}
|
|
1978
2008
|
Object.defineProperty(FieldDescriptor.prototype, "name", {
|
|
@@ -1995,6 +2025,18 @@
|
|
|
1995
2025
|
enumerable: false,
|
|
1996
2026
|
configurable: true
|
|
1997
2027
|
});
|
|
2028
|
+
Object.defineProperty(FieldDescriptor.prototype, "validating", {
|
|
2029
|
+
get: function () { return this._onValidation; },
|
|
2030
|
+
set: function (isValidating) { this._onValidation = isValidating; },
|
|
2031
|
+
enumerable: false,
|
|
2032
|
+
configurable: true
|
|
2033
|
+
});
|
|
2034
|
+
FieldDescriptor.prototype.setIntrinsicErrorMessage = function (message) { this._intrinsicErrorMessage = message; };
|
|
2035
|
+
Object.defineProperty(FieldDescriptor.prototype, "intrinsicErrorMessage", {
|
|
2036
|
+
set: function (message) { this.setIntrinsicErrorMessage(message); },
|
|
2037
|
+
enumerable: false,
|
|
2038
|
+
configurable: true
|
|
2039
|
+
});
|
|
1998
2040
|
Object.defineProperty(FieldDescriptor.prototype, "fieldValue", {
|
|
1999
2041
|
get: function () { return this.getValue(); },
|
|
2000
2042
|
enumerable: false,
|
|
@@ -2025,9 +2067,29 @@
|
|
|
2025
2067
|
enumerable: false,
|
|
2026
2068
|
configurable: true
|
|
2027
2069
|
});
|
|
2028
|
-
FieldDescriptor.prototype.notifyEditionPartial = function () {
|
|
2029
|
-
|
|
2030
|
-
|
|
2070
|
+
FieldDescriptor.prototype.notifyEditionPartial = function () {
|
|
2071
|
+
var intrinsicValidation = true;
|
|
2072
|
+
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
|
|
2073
|
+
};
|
|
2074
|
+
FieldDescriptor.prototype.notifyEditionFinish = function () {
|
|
2075
|
+
var intrinsicValidation = true;
|
|
2076
|
+
var fieldExpression = (this.fieldType === FIELD_TYPES.email) ? EMAIL_FORMAT : this.fieldFormat;
|
|
2077
|
+
var fieldFormat = new RegExp(fieldExpression);
|
|
2078
|
+
var fieldValue = this.getValue();
|
|
2079
|
+
if (fieldValue && fieldFormat) {
|
|
2080
|
+
intrinsicValidation = fieldFormat.test(fieldValue);
|
|
2081
|
+
if (!intrinsicValidation) {
|
|
2082
|
+
var message = (this.fieldType === FIELD_TYPES.email)
|
|
2083
|
+
? "El valor de " + this.fieldTitle + " no corresponde a un correo v\u00E1lido"
|
|
2084
|
+
: "El valor de " + this.fieldTitle + " no se ajusta al formato establecido";
|
|
2085
|
+
this.setError('99', message);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
|
|
2089
|
+
};
|
|
2090
|
+
FieldDescriptor.prototype.notifyEditionDetailRequest = function () {
|
|
2091
|
+
this._detailRequest.next(this.fieldCode);
|
|
2092
|
+
};
|
|
2031
2093
|
FieldDescriptor.prototype.showLabel = function () { this.visibleLabel = true; };
|
|
2032
2094
|
FieldDescriptor.prototype.hideLabel = function () { this.visibleLabel = false; };
|
|
2033
2095
|
FieldDescriptor.prototype.changed = function () { this.hasChanged = true; };
|
|
@@ -2044,11 +2106,35 @@
|
|
|
2044
2106
|
if (editable === void 0) { editable = true; }
|
|
2045
2107
|
(editable) ? this.enable() : this.disable();
|
|
2046
2108
|
};
|
|
2047
|
-
FieldDescriptor.prototype.
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2109
|
+
FieldDescriptor.prototype.setError = function (code, message, type) {
|
|
2110
|
+
if (type === void 0) { type = 'error'; }
|
|
2111
|
+
this.errorType = (code === '00') ? '' : type;
|
|
2112
|
+
this.errorCode = code;
|
|
2113
|
+
this.errorMessage = message;
|
|
2114
|
+
};
|
|
2115
|
+
FieldDescriptor.prototype.getError = function () { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; };
|
|
2116
|
+
Object.defineProperty(FieldDescriptor.prototype, "error", {
|
|
2117
|
+
get: function () { return this.getError(); },
|
|
2118
|
+
set: function (errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); },
|
|
2119
|
+
enumerable: false,
|
|
2120
|
+
configurable: true
|
|
2121
|
+
});
|
|
2122
|
+
FieldDescriptor.prototype.getErrorCode = function () { return this.getError().code; };
|
|
2123
|
+
FieldDescriptor.prototype.setErrorCode = function (code) { this.setError(code, this.errorMessage); };
|
|
2124
|
+
FieldDescriptor.prototype.getErrorMessage = function () { return this.getError().message; };
|
|
2125
|
+
FieldDescriptor.prototype.setErrorMessage = function (msg) { this.setError(this.errorCode, msg); };
|
|
2126
|
+
FieldDescriptor.prototype.isEmpty = function () {
|
|
2127
|
+
var fieldCurrentValue = this.getValue();
|
|
2128
|
+
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
2129
|
+
return true;
|
|
2130
|
+
}
|
|
2131
|
+
if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
|
|
2132
|
+
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
2133
|
+
return true;
|
|
2134
|
+
}
|
|
2135
|
+
;
|
|
2136
|
+
return fieldCurrentValue === '';
|
|
2137
|
+
};
|
|
2052
2138
|
FieldDescriptor.prototype.getValue = function () {
|
|
2053
2139
|
var _a;
|
|
2054
2140
|
switch (this.fieldType) {
|
|
@@ -2721,6 +2807,15 @@
|
|
|
2721
2807
|
var fieldObject = this.getFieldObject(fieldCode);
|
|
2722
2808
|
return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
|
|
2723
2809
|
};
|
|
2810
|
+
FormStructureAndData.prototype.setFieldError = function (code, message, type) {
|
|
2811
|
+
if (type === void 0) { type = 'error'; }
|
|
2812
|
+
var fieldObject = this.getFieldObject(code);
|
|
2813
|
+
return (fieldObject) ? fieldObject.setError(code, message, type) : null;
|
|
2814
|
+
};
|
|
2815
|
+
FormStructureAndData.prototype.setFieldIntrinsicErrorMessage = function (code, message) {
|
|
2816
|
+
var fieldObject = this.getFieldObject(code);
|
|
2817
|
+
return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
|
|
2818
|
+
};
|
|
2724
2819
|
FormStructureAndData.prototype.setFieldRequired = function (fieldCode, required) {
|
|
2725
2820
|
var fieldObject = this.getFieldObject(fieldCode);
|
|
2726
2821
|
return (fieldObject) ? fieldObject.required = required : null;
|
|
@@ -3223,6 +3318,11 @@
|
|
|
3223
3318
|
BasicFormComponent.prototype.setFieldValue = function (fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); };
|
|
3224
3319
|
BasicFormComponent.prototype.setFieldRequired = function (fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); };
|
|
3225
3320
|
BasicFormComponent.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); };
|
|
3321
|
+
BasicFormComponent.prototype.setFieldError = function (code, message, type) {
|
|
3322
|
+
if (type === void 0) { type = 'error'; }
|
|
3323
|
+
return this.formStructure.setFieldError(code, message, type);
|
|
3324
|
+
};
|
|
3325
|
+
BasicFormComponent.prototype.setFieldIntrinsicErrorMessage = function (code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); };
|
|
3226
3326
|
BasicFormComponent.prototype.setFieldOptions = function (fieldCode, optionsArray, idAttribute, nameAttribute) {
|
|
3227
3327
|
return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
|
|
3228
3328
|
};
|
|
@@ -3441,8 +3541,14 @@
|
|
|
3441
3541
|
var formFields = this.formStructure.getFields();
|
|
3442
3542
|
if (Array.isArray(formFields)) {
|
|
3443
3543
|
formFields.forEach(function (field) {
|
|
3444
|
-
field.editionFinish.subscribe(function (
|
|
3445
|
-
|
|
3544
|
+
field.editionFinish.subscribe(function (event) {
|
|
3545
|
+
var code = event.code, intrinsicValidation = event.intrinsicValidation;
|
|
3546
|
+
_this.startFieldValidation(code, intrinsicValidation);
|
|
3547
|
+
});
|
|
3548
|
+
field.editionPartial.subscribe(function (event) {
|
|
3549
|
+
var code = event.code, intrinsicValidation = event.intrinsicValidation;
|
|
3550
|
+
_this.startFieldInputValidation(code, intrinsicValidation);
|
|
3551
|
+
});
|
|
3446
3552
|
field.detailRequest.subscribe(function (code) { return _this.showFieldInfo(code); });
|
|
3447
3553
|
});
|
|
3448
3554
|
}
|
|
@@ -3909,7 +4015,8 @@
|
|
|
3909
4015
|
_this.fieldValidationsFinish[fieldCode].push(callbackMethod);
|
|
3910
4016
|
});
|
|
3911
4017
|
};
|
|
3912
|
-
BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode) {
|
|
4018
|
+
BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode, intrinsicValidation) {
|
|
4019
|
+
if (intrinsicValidation === void 0) { intrinsicValidation = true; }
|
|
3913
4020
|
return __awaiter(this, void 0, void 0, function () {
|
|
3914
4021
|
var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_1, validationCallbacks_1_1, validationMethod, continueValidationPromise;
|
|
3915
4022
|
var e_10, _g;
|
|
@@ -3948,7 +4055,8 @@
|
|
|
3948
4055
|
});
|
|
3949
4056
|
});
|
|
3950
4057
|
};
|
|
3951
|
-
BasicFormComponent.prototype.startFieldValidation = function (fieldCode) {
|
|
4058
|
+
BasicFormComponent.prototype.startFieldValidation = function (fieldCode, intrinsicValidation) {
|
|
4059
|
+
if (intrinsicValidation === void 0) { intrinsicValidation = true; }
|
|
3952
4060
|
return __awaiter(this, void 0, void 0, function () {
|
|
3953
4061
|
var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_2, validationCallbacks_2_1, validationMethod, clientValidationPromise, clientValidationResults, continueValidation;
|
|
3954
4062
|
var e_11, _g;
|
|
@@ -3956,7 +4064,7 @@
|
|
|
3956
4064
|
switch (_h.label) {
|
|
3957
4065
|
case 0:
|
|
3958
4066
|
fieldToValidate = this.getField(fieldCode);
|
|
3959
|
-
if (!fieldToValidate) {
|
|
4067
|
+
if (!fieldToValidate || !intrinsicValidation) {
|
|
3960
4068
|
return [2 /*return*/];
|
|
3961
4069
|
}
|
|
3962
4070
|
fieldToValidate.setErrorMessage('');
|
|
@@ -4004,6 +4112,7 @@
|
|
|
4004
4112
|
finish = true;
|
|
4005
4113
|
validationResult = null;
|
|
4006
4114
|
if (!fieldObj.backend) return [3 /*break*/, 2];
|
|
4115
|
+
fieldObj.validating = true;
|
|
4007
4116
|
return [4 /*yield*/, this
|
|
4008
4117
|
.requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode)];
|
|
4009
4118
|
case 1:
|
|
@@ -4021,7 +4130,9 @@
|
|
|
4021
4130
|
fieldObj.setErrorMessage(this.errorMessage);
|
|
4022
4131
|
this.displayValidationServerError();
|
|
4023
4132
|
_g.label = 5;
|
|
4024
|
-
case 5:
|
|
4133
|
+
case 5:
|
|
4134
|
+
fieldObj.validating = false;
|
|
4135
|
+
return [2 /*return*/];
|
|
4025
4136
|
}
|
|
4026
4137
|
});
|
|
4027
4138
|
});
|