tuain-ng-forms-lib 0.12.19 → 0.12.23
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/README.md +2 -1
- package/bundles/tuain-ng-forms-lib.umd.js +137 -22
- package/bundles/tuain-ng-forms-lib.umd.js.map +1 -1
- package/esm2015/lib/classes/forms/field.js +90 -13
- package/esm2015/lib/classes/forms/form.js +9 -1
- package/esm2015/lib/classes/forms/table/table.js +5 -5
- package/esm2015/lib/components/forms/basic-form.js +16 -6
- package/fesm2015/tuain-ng-forms-lib.js +116 -21
- package/fesm2015/tuain-ng-forms-lib.js.map +1 -1
- package/lib/classes/forms/field.d.ts +27 -4
- 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
package/README.md
CHANGED
|
@@ -306,6 +306,7 @@ This set of methods allow subclass to access and modify fields in the form.
|
|
|
306
306
|
| `setFieldValue` | Change the current value of a field |
|
|
307
307
|
| `setFieldErrorMessage` | Defines an error message for a field |
|
|
308
308
|
| `setFieldOptions` | Define the posible values of the field with an array of values and description text |
|
|
309
|
+
| `setFieldRequired` | Change an status attribute of the field to determine if it is required |
|
|
309
310
|
| `applyProcessToFieldSet` | Execute a process on all the fields specified in an array, section or sub-section. If the fields are not specified, the execition will be over the whole set of fields in the form `(processFunc, fieldArray?, sectionCode?, subSectionCode?)`|
|
|
310
311
|
| `cleanFields` | Clean all the fields specified in an array, section or sub-section using their default value. If the fields are not specified, the execition will be over the whole set of fields in the form `(fieldArray?, sectionCode?, subSectionCode?)`|
|
|
311
312
|
| `getRequiredFields` | Obtain all the required fields specified in an array, section or sub-section using their default value. If the fields are not specified, the execition will be over the whole set of fields in the form `(fieldArray?, sectionCode?, subSectionCode?)`|
|
|
@@ -408,4 +409,4 @@ but common operations in the forms.
|
|
|
408
409
|
|
|
409
410
|
## License
|
|
410
411
|
|
|
411
|
-
[MIT](https://choosealicense.com/licenses/mit/)
|
|
412
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
@@ -1365,17 +1365,17 @@
|
|
|
1365
1365
|
if (!this.sorting.columnName || !this.sorting.direction) {
|
|
1366
1366
|
return;
|
|
1367
1367
|
}
|
|
1368
|
-
this.tableRecords
|
|
1369
|
-
|
|
1368
|
+
this.tableRecords.sort(function (a, b) { return _this.recordCompare(a, b, _this.sorting.columnName, _this.sorting.direction); });
|
|
1369
|
+
this.updateVisibleRecords();
|
|
1370
1370
|
};
|
|
1371
1371
|
RecordTable.prototype.recordCompare = function (recordA, recordB, columnCompare, direction) {
|
|
1372
1372
|
var recordAColumn = recordA.getFieldValue(columnCompare);
|
|
1373
1373
|
var recordBColumn = recordB.getFieldValue(columnCompare);
|
|
1374
1374
|
var result = 0;
|
|
1375
|
-
if (recordAColumn
|
|
1375
|
+
if (recordAColumn < recordBColumn) {
|
|
1376
1376
|
result = -1;
|
|
1377
1377
|
}
|
|
1378
|
-
else if (recordAColumn
|
|
1378
|
+
else if (recordAColumn > recordBColumn) {
|
|
1379
1379
|
result = 1;
|
|
1380
1380
|
}
|
|
1381
1381
|
return direction === componentConstants.TABLE_SORT_ASCENDING ? result : -result;
|
|
@@ -1937,13 +1937,41 @@
|
|
|
1937
1937
|
var FIELD_TOOLTIP = 'tooltipText';
|
|
1938
1938
|
var FIELD_INFO = 'info';
|
|
1939
1939
|
var FIELD_EDITABLE = 'editable';
|
|
1940
|
+
var FIELD_TYPES = {
|
|
1941
|
+
array: 'ARRAY',
|
|
1942
|
+
check: 'CHECK',
|
|
1943
|
+
date: 'DATE',
|
|
1944
|
+
daterange: 'DATERANGE',
|
|
1945
|
+
time: 'TIME',
|
|
1946
|
+
timerange: 'TIMERANGE',
|
|
1947
|
+
map: 'MAP',
|
|
1948
|
+
number: 'NUMBER',
|
|
1949
|
+
decimal: 'DECIMAL',
|
|
1950
|
+
currency: 'CURRENCY',
|
|
1951
|
+
select: 'SELECT',
|
|
1952
|
+
typeahead: 'TYPEAHEAD',
|
|
1953
|
+
text: 'TEXT',
|
|
1954
|
+
password: 'PASSWORD',
|
|
1955
|
+
label: 'LABEL',
|
|
1956
|
+
html: 'HTML',
|
|
1957
|
+
title: 'TITLE',
|
|
1958
|
+
message: 'MESSAGE',
|
|
1959
|
+
link: 'LINK',
|
|
1960
|
+
warning: 'WARNING',
|
|
1961
|
+
avatar: 'AVATAR',
|
|
1962
|
+
email: 'EMAIL',
|
|
1963
|
+
phone: 'PHONE',
|
|
1964
|
+
};
|
|
1965
|
+
var FIELD_TYPES_FORMATS = {
|
|
1966
|
+
EMAIL: new RegExp('^\\w+([\\.-]?\\w+)@\\w+([\\.-]?\\w+)(\\.\\w{2,3})+$'),
|
|
1967
|
+
};
|
|
1940
1968
|
var STD_MAX_LENGTH = 50;
|
|
1941
1969
|
var BIG_MAX_LENGTH = 500;
|
|
1942
1970
|
var FieldDescriptor = /** @class */ (function (_super) {
|
|
1943
1971
|
__extends(FieldDescriptor, _super);
|
|
1944
1972
|
function FieldDescriptor(inputFieldReceived) {
|
|
1945
1973
|
var _this = this;
|
|
1946
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1974
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1947
1975
|
_this = _super.call(this, inputFieldReceived) || this;
|
|
1948
1976
|
_this._editionFinish = new rxjs.Subject();
|
|
1949
1977
|
_this._editionPartial = new rxjs.Subject();
|
|
@@ -1961,7 +1989,12 @@
|
|
|
1961
1989
|
var defaultTypeAlignment = (tableFieldStyles[_this.fieldType] != null) ? tableFieldStyles[_this.fieldType]['text-align'] : 'left';
|
|
1962
1990
|
_this.fieldAlignment = (fieldReceived.alignment != null) ? fieldReceived.alignment.toLowerCase() : defaultTypeAlignment;
|
|
1963
1991
|
_this.fieldInfo = fieldReceived.info || '';
|
|
1964
|
-
|
|
1992
|
+
try {
|
|
1993
|
+
_this.fieldFormat = (fieldReceived.format) ? new RegExp(fieldReceived.format) : null;
|
|
1994
|
+
}
|
|
1995
|
+
catch (e) {
|
|
1996
|
+
_this.fieldFormat = null;
|
|
1997
|
+
}
|
|
1965
1998
|
_this.validateOnServer = (_c = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.serverAction) !== null && _c !== void 0 ? _c : false;
|
|
1966
1999
|
_this.customAttributes = (_d = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.customAttributes) !== null && _d !== void 0 ? _d : null;
|
|
1967
2000
|
_this.setVisibility(fieldReceived.visible);
|
|
@@ -1970,9 +2003,12 @@
|
|
|
1970
2003
|
_this.defaultEditable = _this.enabled;
|
|
1971
2004
|
_this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
|
|
1972
2005
|
_this.errorMessage = fieldReceived.errorMessage || '';
|
|
1973
|
-
_this.errorCode = fieldReceived.errorCode
|
|
1974
|
-
_this.outputOnly = (
|
|
2006
|
+
_this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
|
|
2007
|
+
_this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
|
|
1975
2008
|
_this.setFieldOptions(fieldReceived.fieldOptions);
|
|
2009
|
+
_this._intrinsicErrorMessage = (_this.fieldType === FIELD_TYPES.email)
|
|
2010
|
+
? "El valor de " + _this.fieldTitle + " no corresponde a un correo v\u00E1lido"
|
|
2011
|
+
: "El valor de " + _this.fieldTitle + " no se ajusta al formato establecido";
|
|
1976
2012
|
return _this;
|
|
1977
2013
|
}
|
|
1978
2014
|
Object.defineProperty(FieldDescriptor.prototype, "name", {
|
|
@@ -1995,6 +2031,18 @@
|
|
|
1995
2031
|
enumerable: false,
|
|
1996
2032
|
configurable: true
|
|
1997
2033
|
});
|
|
2034
|
+
Object.defineProperty(FieldDescriptor.prototype, "validating", {
|
|
2035
|
+
get: function () { return this._onValidation; },
|
|
2036
|
+
set: function (isValidating) { this._onValidation = isValidating; },
|
|
2037
|
+
enumerable: false,
|
|
2038
|
+
configurable: true
|
|
2039
|
+
});
|
|
2040
|
+
FieldDescriptor.prototype.setIntrinsicErrorMessage = function (message) { this._intrinsicErrorMessage = message; };
|
|
2041
|
+
Object.defineProperty(FieldDescriptor.prototype, "intrinsicErrorMessage", {
|
|
2042
|
+
set: function (message) { this.setIntrinsicErrorMessage(message); },
|
|
2043
|
+
enumerable: false,
|
|
2044
|
+
configurable: true
|
|
2045
|
+
});
|
|
1998
2046
|
Object.defineProperty(FieldDescriptor.prototype, "fieldValue", {
|
|
1999
2047
|
get: function () { return this.getValue(); },
|
|
2000
2048
|
enumerable: false,
|
|
@@ -2025,9 +2073,27 @@
|
|
|
2025
2073
|
enumerable: false,
|
|
2026
2074
|
configurable: true
|
|
2027
2075
|
});
|
|
2028
|
-
FieldDescriptor.prototype.notifyEditionPartial = function () {
|
|
2029
|
-
|
|
2030
|
-
|
|
2076
|
+
FieldDescriptor.prototype.notifyEditionPartial = function () {
|
|
2077
|
+
var intrinsicValidation = true;
|
|
2078
|
+
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
|
|
2079
|
+
};
|
|
2080
|
+
FieldDescriptor.prototype.notifyEditionFinish = function () {
|
|
2081
|
+
var _a, _b, _c, _d;
|
|
2082
|
+
var intrinsicValidation = true;
|
|
2083
|
+
var fieldDefaultFormat = (_a = FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType]) !== null && _a !== void 0 ? _a : null;
|
|
2084
|
+
var fieldValue = this.getValue();
|
|
2085
|
+
if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
|
|
2086
|
+
intrinsicValidation = ((_b = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _b !== void 0 ? _b : true)
|
|
2087
|
+
&& ((_d = (_c = this.fieldFormat) === null || _c === void 0 ? void 0 : _c.test(fieldValue)) !== null && _d !== void 0 ? _d : true);
|
|
2088
|
+
if (!intrinsicValidation) {
|
|
2089
|
+
this.setError('99', this._intrinsicErrorMessage);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
|
|
2093
|
+
};
|
|
2094
|
+
FieldDescriptor.prototype.notifyEditionDetailRequest = function () {
|
|
2095
|
+
this._detailRequest.next(this.fieldCode);
|
|
2096
|
+
};
|
|
2031
2097
|
FieldDescriptor.prototype.showLabel = function () { this.visibleLabel = true; };
|
|
2032
2098
|
FieldDescriptor.prototype.hideLabel = function () { this.visibleLabel = false; };
|
|
2033
2099
|
FieldDescriptor.prototype.changed = function () { this.hasChanged = true; };
|
|
@@ -2044,11 +2110,35 @@
|
|
|
2044
2110
|
if (editable === void 0) { editable = true; }
|
|
2045
2111
|
(editable) ? this.enable() : this.disable();
|
|
2046
2112
|
};
|
|
2047
|
-
FieldDescriptor.prototype.
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2113
|
+
FieldDescriptor.prototype.setError = function (code, message, type) {
|
|
2114
|
+
if (type === void 0) { type = 'error'; }
|
|
2115
|
+
this.errorType = (code === '00') ? '' : type;
|
|
2116
|
+
this.errorCode = code;
|
|
2117
|
+
this.errorMessage = message;
|
|
2118
|
+
};
|
|
2119
|
+
FieldDescriptor.prototype.getError = function () { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; };
|
|
2120
|
+
Object.defineProperty(FieldDescriptor.prototype, "error", {
|
|
2121
|
+
get: function () { return this.getError(); },
|
|
2122
|
+
set: function (errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); },
|
|
2123
|
+
enumerable: false,
|
|
2124
|
+
configurable: true
|
|
2125
|
+
});
|
|
2126
|
+
FieldDescriptor.prototype.getErrorCode = function () { return this.getError().code; };
|
|
2127
|
+
FieldDescriptor.prototype.setErrorCode = function (code) { this.setError(code, this.errorMessage); };
|
|
2128
|
+
FieldDescriptor.prototype.getErrorMessage = function () { return this.getError().message; };
|
|
2129
|
+
FieldDescriptor.prototype.setErrorMessage = function (msg) { this.setError(this.errorCode, msg); };
|
|
2130
|
+
FieldDescriptor.prototype.isEmpty = function () {
|
|
2131
|
+
var fieldCurrentValue = this.getValue();
|
|
2132
|
+
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
2133
|
+
return true;
|
|
2134
|
+
}
|
|
2135
|
+
if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
|
|
2136
|
+
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
2137
|
+
return true;
|
|
2138
|
+
}
|
|
2139
|
+
;
|
|
2140
|
+
return fieldCurrentValue === '';
|
|
2141
|
+
};
|
|
2052
2142
|
FieldDescriptor.prototype.getValue = function () {
|
|
2053
2143
|
var _a;
|
|
2054
2144
|
switch (this.fieldType) {
|
|
@@ -2721,6 +2811,15 @@
|
|
|
2721
2811
|
var fieldObject = this.getFieldObject(fieldCode);
|
|
2722
2812
|
return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
|
|
2723
2813
|
};
|
|
2814
|
+
FormStructureAndData.prototype.setFieldError = function (code, message, type) {
|
|
2815
|
+
if (type === void 0) { type = 'error'; }
|
|
2816
|
+
var fieldObject = this.getFieldObject(code);
|
|
2817
|
+
return (fieldObject) ? fieldObject.setError(code, message, type) : null;
|
|
2818
|
+
};
|
|
2819
|
+
FormStructureAndData.prototype.setFieldIntrinsicErrorMessage = function (code, message) {
|
|
2820
|
+
var fieldObject = this.getFieldObject(code);
|
|
2821
|
+
return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
|
|
2822
|
+
};
|
|
2724
2823
|
FormStructureAndData.prototype.setFieldRequired = function (fieldCode, required) {
|
|
2725
2824
|
var fieldObject = this.getFieldObject(fieldCode);
|
|
2726
2825
|
return (fieldObject) ? fieldObject.required = required : null;
|
|
@@ -3223,6 +3322,11 @@
|
|
|
3223
3322
|
BasicFormComponent.prototype.setFieldValue = function (fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); };
|
|
3224
3323
|
BasicFormComponent.prototype.setFieldRequired = function (fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); };
|
|
3225
3324
|
BasicFormComponent.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); };
|
|
3325
|
+
BasicFormComponent.prototype.setFieldError = function (code, message, type) {
|
|
3326
|
+
if (type === void 0) { type = 'error'; }
|
|
3327
|
+
return this.formStructure.setFieldError(code, message, type);
|
|
3328
|
+
};
|
|
3329
|
+
BasicFormComponent.prototype.setFieldIntrinsicErrorMessage = function (code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); };
|
|
3226
3330
|
BasicFormComponent.prototype.setFieldOptions = function (fieldCode, optionsArray, idAttribute, nameAttribute) {
|
|
3227
3331
|
return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
|
|
3228
3332
|
};
|
|
@@ -3441,8 +3545,14 @@
|
|
|
3441
3545
|
var formFields = this.formStructure.getFields();
|
|
3442
3546
|
if (Array.isArray(formFields)) {
|
|
3443
3547
|
formFields.forEach(function (field) {
|
|
3444
|
-
field.editionFinish.subscribe(function (
|
|
3445
|
-
|
|
3548
|
+
field.editionFinish.subscribe(function (event) {
|
|
3549
|
+
var code = event.code, intrinsicValidation = event.intrinsicValidation;
|
|
3550
|
+
_this.startFieldValidation(code, intrinsicValidation);
|
|
3551
|
+
});
|
|
3552
|
+
field.editionPartial.subscribe(function (event) {
|
|
3553
|
+
var code = event.code, intrinsicValidation = event.intrinsicValidation;
|
|
3554
|
+
_this.startFieldInputValidation(code, intrinsicValidation);
|
|
3555
|
+
});
|
|
3446
3556
|
field.detailRequest.subscribe(function (code) { return _this.showFieldInfo(code); });
|
|
3447
3557
|
});
|
|
3448
3558
|
}
|
|
@@ -3909,7 +4019,8 @@
|
|
|
3909
4019
|
_this.fieldValidationsFinish[fieldCode].push(callbackMethod);
|
|
3910
4020
|
});
|
|
3911
4021
|
};
|
|
3912
|
-
BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode) {
|
|
4022
|
+
BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode, intrinsicValidation) {
|
|
4023
|
+
if (intrinsicValidation === void 0) { intrinsicValidation = true; }
|
|
3913
4024
|
return __awaiter(this, void 0, void 0, function () {
|
|
3914
4025
|
var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_1, validationCallbacks_1_1, validationMethod, continueValidationPromise;
|
|
3915
4026
|
var e_10, _g;
|
|
@@ -3948,7 +4059,8 @@
|
|
|
3948
4059
|
});
|
|
3949
4060
|
});
|
|
3950
4061
|
};
|
|
3951
|
-
BasicFormComponent.prototype.startFieldValidation = function (fieldCode) {
|
|
4062
|
+
BasicFormComponent.prototype.startFieldValidation = function (fieldCode, intrinsicValidation) {
|
|
4063
|
+
if (intrinsicValidation === void 0) { intrinsicValidation = true; }
|
|
3952
4064
|
return __awaiter(this, void 0, void 0, function () {
|
|
3953
4065
|
var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_2, validationCallbacks_2_1, validationMethod, clientValidationPromise, clientValidationResults, continueValidation;
|
|
3954
4066
|
var e_11, _g;
|
|
@@ -3956,7 +4068,7 @@
|
|
|
3956
4068
|
switch (_h.label) {
|
|
3957
4069
|
case 0:
|
|
3958
4070
|
fieldToValidate = this.getField(fieldCode);
|
|
3959
|
-
if (!fieldToValidate) {
|
|
4071
|
+
if (!fieldToValidate || !intrinsicValidation) {
|
|
3960
4072
|
return [2 /*return*/];
|
|
3961
4073
|
}
|
|
3962
4074
|
fieldToValidate.setErrorMessage('');
|
|
@@ -4004,6 +4116,7 @@
|
|
|
4004
4116
|
finish = true;
|
|
4005
4117
|
validationResult = null;
|
|
4006
4118
|
if (!fieldObj.backend) return [3 /*break*/, 2];
|
|
4119
|
+
fieldObj.validating = true;
|
|
4007
4120
|
return [4 /*yield*/, this
|
|
4008
4121
|
.requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode)];
|
|
4009
4122
|
case 1:
|
|
@@ -4021,7 +4134,9 @@
|
|
|
4021
4134
|
fieldObj.setErrorMessage(this.errorMessage);
|
|
4022
4135
|
this.displayValidationServerError();
|
|
4023
4136
|
_g.label = 5;
|
|
4024
|
-
case 5:
|
|
4137
|
+
case 5:
|
|
4138
|
+
fieldObj.validating = false;
|
|
4139
|
+
return [2 /*return*/];
|
|
4025
4140
|
}
|
|
4026
4141
|
});
|
|
4027
4142
|
});
|