tuain-ng-forms-lib 0.12.18 → 0.12.22
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 +139 -22
- package/bundles/tuain-ng-forms-lib.umd.js.map +1 -1
- package/esm2015/lib/classes/forms/field.js +87 -13
- package/esm2015/lib/classes/forms/form.js +13 -1
- package/esm2015/lib/classes/forms/table/table.js +5 -5
- package/esm2015/lib/components/forms/basic-form.js +17 -6
- package/fesm2015/tuain-ng-forms-lib.js +118 -21
- 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 +3 -0
- package/lib/components/forms/basic-form.d.ts +5 -2
- package/package.json +1 -1
- package/tuain-ng-forms-lib.metadata.json +1 -1
|
@@ -871,17 +871,17 @@ class RecordTable extends FormElement {
|
|
|
871
871
|
if (!this.sorting.columnName || !this.sorting.direction) {
|
|
872
872
|
return;
|
|
873
873
|
}
|
|
874
|
-
this.tableRecords
|
|
875
|
-
|
|
874
|
+
this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
|
|
875
|
+
this.updateVisibleRecords();
|
|
876
876
|
}
|
|
877
877
|
recordCompare(recordA, recordB, columnCompare, direction) {
|
|
878
878
|
const recordAColumn = recordA.getFieldValue(columnCompare);
|
|
879
879
|
const recordBColumn = recordB.getFieldValue(columnCompare);
|
|
880
880
|
let result = 0;
|
|
881
|
-
if (recordAColumn
|
|
881
|
+
if (recordAColumn < recordBColumn) {
|
|
882
882
|
result = -1;
|
|
883
883
|
}
|
|
884
|
-
else if (recordAColumn
|
|
884
|
+
else if (recordAColumn > recordBColumn) {
|
|
885
885
|
result = 1;
|
|
886
886
|
}
|
|
887
887
|
return direction === componentConstants.TABLE_SORT_ASCENDING ? result : -result;
|
|
@@ -1349,11 +1349,39 @@ const FIELD_ERR_MSG = 'errorMessage';
|
|
|
1349
1349
|
const FIELD_TOOLTIP = 'tooltipText';
|
|
1350
1350
|
const FIELD_INFO = 'info';
|
|
1351
1351
|
const FIELD_EDITABLE = 'editable';
|
|
1352
|
+
const FIELD_TYPES = {
|
|
1353
|
+
array: 'ARRAY',
|
|
1354
|
+
check: 'CHECK',
|
|
1355
|
+
date: 'DATE',
|
|
1356
|
+
daterange: 'DATERANGE',
|
|
1357
|
+
time: 'TIME',
|
|
1358
|
+
timerange: 'TIMERANGE',
|
|
1359
|
+
map: 'MAP',
|
|
1360
|
+
number: 'NUMBER',
|
|
1361
|
+
decimal: 'DECIMAL',
|
|
1362
|
+
currency: 'CURRENCY',
|
|
1363
|
+
select: 'SELECT',
|
|
1364
|
+
typeahead: 'TYPEAHEAD',
|
|
1365
|
+
text: 'TEXT',
|
|
1366
|
+
password: 'PASSWORD',
|
|
1367
|
+
label: 'LABEL',
|
|
1368
|
+
html: 'HTML',
|
|
1369
|
+
title: 'TITLE',
|
|
1370
|
+
message: 'MESSAGE',
|
|
1371
|
+
link: 'LINK',
|
|
1372
|
+
warning: 'WARNING',
|
|
1373
|
+
avatar: 'AVATAR',
|
|
1374
|
+
email: 'EMAIL',
|
|
1375
|
+
phone: 'PHONE',
|
|
1376
|
+
};
|
|
1377
|
+
const FIELD_TYPES_FORMATS = {
|
|
1378
|
+
EMAIL: '^\\w+([\\.-]?\\w+)@\\w+([\\.-]?\\w+)(\\.\\w{2,3})+$',
|
|
1379
|
+
};
|
|
1352
1380
|
const STD_MAX_LENGTH = 50;
|
|
1353
1381
|
const BIG_MAX_LENGTH = 500;
|
|
1354
1382
|
class FieldDescriptor extends FormElement {
|
|
1355
1383
|
constructor(inputFieldReceived) {
|
|
1356
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1384
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1357
1385
|
super(inputFieldReceived);
|
|
1358
1386
|
this._editionFinish = new Subject();
|
|
1359
1387
|
this._editionPartial = new Subject();
|
|
@@ -1371,7 +1399,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1371
1399
|
const defaultTypeAlignment = (tableFieldStyles[this.fieldType] != null) ? tableFieldStyles[this.fieldType]['text-align'] : 'left';
|
|
1372
1400
|
this.fieldAlignment = (fieldReceived.alignment != null) ? fieldReceived.alignment.toLowerCase() : defaultTypeAlignment;
|
|
1373
1401
|
this.fieldInfo = fieldReceived.info || '';
|
|
1374
|
-
this.fieldFormat = fieldReceived.format ||
|
|
1402
|
+
this.fieldFormat = fieldReceived.format || null;
|
|
1375
1403
|
this.validateOnServer = (_c = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.serverAction) !== null && _c !== void 0 ? _c : false;
|
|
1376
1404
|
this.customAttributes = (_d = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.customAttributes) !== null && _d !== void 0 ? _d : null;
|
|
1377
1405
|
this.setVisibility(fieldReceived.visible);
|
|
@@ -1380,14 +1408,21 @@ class FieldDescriptor extends FormElement {
|
|
|
1380
1408
|
this.defaultEditable = this.enabled;
|
|
1381
1409
|
this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
|
|
1382
1410
|
this.errorMessage = fieldReceived.errorMessage || '';
|
|
1383
|
-
this.errorCode = fieldReceived.errorCode
|
|
1384
|
-
this.outputOnly = (
|
|
1411
|
+
this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
|
|
1412
|
+
this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
|
|
1385
1413
|
this.setFieldOptions(fieldReceived.fieldOptions);
|
|
1414
|
+
this._intrinsicErrorMessage = (this.fieldType === FIELD_TYPES.email)
|
|
1415
|
+
? `El valor de ${this.fieldTitle} no corresponde a un correo válido`
|
|
1416
|
+
: `El valor de ${this.fieldTitle} no se ajusta al formato establecido`;
|
|
1386
1417
|
}
|
|
1387
1418
|
get name() { return this.fieldCode; }
|
|
1388
1419
|
get editionFinish() { return this._editionFinish; }
|
|
1389
1420
|
get editionPartial() { return this._editionPartial; }
|
|
1390
1421
|
get detailRequest() { return this._detailRequest; }
|
|
1422
|
+
get validating() { return this._onValidation; }
|
|
1423
|
+
set validating(isValidating) { this._onValidation = isValidating; }
|
|
1424
|
+
setIntrinsicErrorMessage(message) { this._intrinsicErrorMessage = message; }
|
|
1425
|
+
set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
|
|
1391
1426
|
get fieldValue() { return this.getValue(); }
|
|
1392
1427
|
get required() { return this.fieldRequired; }
|
|
1393
1428
|
set required(required) { this.fieldRequired = required !== null && required !== void 0 ? required : false; }
|
|
@@ -1402,9 +1437,29 @@ class FieldDescriptor extends FormElement {
|
|
|
1402
1437
|
}
|
|
1403
1438
|
get value() { return this.getValue(); }
|
|
1404
1439
|
set value(newValue) { this.setValue(newValue); }
|
|
1405
|
-
notifyEditionPartial() {
|
|
1406
|
-
|
|
1407
|
-
|
|
1440
|
+
notifyEditionPartial() {
|
|
1441
|
+
const intrinsicValidation = true;
|
|
1442
|
+
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
|
|
1443
|
+
}
|
|
1444
|
+
notifyEditionFinish() {
|
|
1445
|
+
var _a, _b;
|
|
1446
|
+
let intrinsicValidation = true;
|
|
1447
|
+
const fieldDefaultFormat = (FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType])
|
|
1448
|
+
? new RegExp(FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType]) : null;
|
|
1449
|
+
const fieldFormat = (this.fieldFormat) ? new RegExp(this.fieldFormat) : null;
|
|
1450
|
+
const fieldValue = this.getValue();
|
|
1451
|
+
if (fieldValue && (fieldDefaultFormat || fieldFormat)) {
|
|
1452
|
+
intrinsicValidation = ((_a = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _a !== void 0 ? _a : true)
|
|
1453
|
+
&& ((_b = fieldFormat === null || fieldFormat === void 0 ? void 0 : fieldFormat.test(fieldValue)) !== null && _b !== void 0 ? _b : true);
|
|
1454
|
+
if (!intrinsicValidation) {
|
|
1455
|
+
this.setError('99', this._intrinsicErrorMessage);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
|
|
1459
|
+
}
|
|
1460
|
+
notifyEditionDetailRequest() {
|
|
1461
|
+
this._detailRequest.next(this.fieldCode);
|
|
1462
|
+
}
|
|
1408
1463
|
showLabel() { this.visibleLabel = true; }
|
|
1409
1464
|
hideLabel() { this.visibleLabel = false; }
|
|
1410
1465
|
changed() { this.hasChanged = true; }
|
|
@@ -1414,11 +1469,30 @@ class FieldDescriptor extends FormElement {
|
|
|
1414
1469
|
get backend() { return this.validateOnServer; }
|
|
1415
1470
|
setVisibleLabel(visibleLabel) { this.visibleLabel = visibleLabel; }
|
|
1416
1471
|
setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1472
|
+
setError(code, message, type = 'error') {
|
|
1473
|
+
this.errorType = (code === '00') ? '' : type;
|
|
1474
|
+
this.errorCode = code;
|
|
1475
|
+
this.errorMessage = message;
|
|
1476
|
+
}
|
|
1477
|
+
getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
|
|
1478
|
+
get error() { return this.getError(); }
|
|
1479
|
+
set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); }
|
|
1480
|
+
getErrorCode() { return this.getError().code; }
|
|
1481
|
+
setErrorCode(code) { this.setError(code, this.errorMessage); }
|
|
1482
|
+
getErrorMessage() { return this.getError().message; }
|
|
1483
|
+
setErrorMessage(msg) { this.setError(this.errorCode, msg); }
|
|
1484
|
+
isEmpty() {
|
|
1485
|
+
const fieldCurrentValue = this.getValue();
|
|
1486
|
+
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
|
|
1490
|
+
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
1491
|
+
return true;
|
|
1492
|
+
}
|
|
1493
|
+
;
|
|
1494
|
+
return fieldCurrentValue === '';
|
|
1495
|
+
}
|
|
1422
1496
|
getValue() {
|
|
1423
1497
|
var _a;
|
|
1424
1498
|
switch (this.fieldType) {
|
|
@@ -1976,6 +2050,18 @@ class FormStructureAndData {
|
|
|
1976
2050
|
const fieldObject = this.getFieldObject(fieldCode);
|
|
1977
2051
|
return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
|
|
1978
2052
|
}
|
|
2053
|
+
setFieldError(code, message, type = 'error') {
|
|
2054
|
+
const fieldObject = this.getFieldObject(code);
|
|
2055
|
+
return (fieldObject) ? fieldObject.setError(code, message, type) : null;
|
|
2056
|
+
}
|
|
2057
|
+
setFieldIntrinsicErrorMessage(code, message) {
|
|
2058
|
+
const fieldObject = this.getFieldObject(code);
|
|
2059
|
+
return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
|
|
2060
|
+
}
|
|
2061
|
+
setFieldRequired(fieldCode, required) {
|
|
2062
|
+
const fieldObject = this.getFieldObject(fieldCode);
|
|
2063
|
+
return (fieldObject) ? fieldObject.required = required : null;
|
|
2064
|
+
}
|
|
1979
2065
|
setFieldErrorMessage(fieldCode, errorMessage) {
|
|
1980
2066
|
const fieldObject = this.getFieldObject(fieldCode);
|
|
1981
2067
|
return (fieldObject) ? fieldObject.setErrorMessage(errorMessage) : null;
|
|
@@ -2350,7 +2436,10 @@ class BasicFormComponent {
|
|
|
2350
2436
|
getFieldsValues(fieldCodesArray) { return this.formStructure.getFieldsValues(fieldCodesArray); }
|
|
2351
2437
|
getFieldOptions(fieldCode) { return this.formStructure.getFieldOptions(fieldCode); }
|
|
2352
2438
|
setFieldValue(fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); }
|
|
2439
|
+
setFieldRequired(fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); }
|
|
2353
2440
|
setFieldErrorMessage(fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); }
|
|
2441
|
+
setFieldError(code, message, type = 'error') { return this.formStructure.setFieldError(code, message, type); }
|
|
2442
|
+
setFieldIntrinsicErrorMessage(code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); }
|
|
2354
2443
|
setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute) {
|
|
2355
2444
|
return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
|
|
2356
2445
|
}
|
|
@@ -2543,8 +2632,14 @@ class BasicFormComponent {
|
|
|
2543
2632
|
const formFields = this.formStructure.getFields();
|
|
2544
2633
|
if (Array.isArray(formFields)) {
|
|
2545
2634
|
formFields.forEach(field => {
|
|
2546
|
-
field.editionFinish.subscribe(
|
|
2547
|
-
|
|
2635
|
+
field.editionFinish.subscribe(event => {
|
|
2636
|
+
const { code, intrinsicValidation } = event;
|
|
2637
|
+
this.startFieldValidation(code, intrinsicValidation);
|
|
2638
|
+
});
|
|
2639
|
+
field.editionPartial.subscribe(event => {
|
|
2640
|
+
const { code, intrinsicValidation } = event;
|
|
2641
|
+
this.startFieldInputValidation(code, intrinsicValidation);
|
|
2642
|
+
});
|
|
2548
2643
|
field.detailRequest.subscribe(code => this.showFieldInfo(code));
|
|
2549
2644
|
});
|
|
2550
2645
|
}
|
|
@@ -2855,7 +2950,7 @@ class BasicFormComponent {
|
|
|
2855
2950
|
this.fieldValidationsFinish[fieldCode].push(callbackMethod);
|
|
2856
2951
|
});
|
|
2857
2952
|
}
|
|
2858
|
-
startFieldInputValidation(fieldCode) {
|
|
2953
|
+
startFieldInputValidation(fieldCode, intrinsicValidation = true) {
|
|
2859
2954
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2860
2955
|
const fieldToValidate = this.getFieldObject(fieldCode);
|
|
2861
2956
|
if (!fieldToValidate) {
|
|
@@ -2874,10 +2969,10 @@ class BasicFormComponent {
|
|
|
2874
2969
|
}
|
|
2875
2970
|
});
|
|
2876
2971
|
}
|
|
2877
|
-
startFieldValidation(fieldCode) {
|
|
2972
|
+
startFieldValidation(fieldCode, intrinsicValidation = true) {
|
|
2878
2973
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2879
2974
|
const fieldToValidate = this.getField(fieldCode);
|
|
2880
|
-
if (!fieldToValidate) {
|
|
2975
|
+
if (!fieldToValidate || !intrinsicValidation) {
|
|
2881
2976
|
return;
|
|
2882
2977
|
}
|
|
2883
2978
|
fieldToValidate.setErrorMessage('');
|
|
@@ -2905,6 +3000,7 @@ class BasicFormComponent {
|
|
|
2905
3000
|
let finish = true;
|
|
2906
3001
|
let validationResult = null;
|
|
2907
3002
|
if (fieldObj.backend) {
|
|
3003
|
+
fieldObj.validating = true;
|
|
2908
3004
|
validationResult = yield this
|
|
2909
3005
|
.requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode);
|
|
2910
3006
|
finish = !this.errorOccured();
|
|
@@ -2917,6 +3013,7 @@ class BasicFormComponent {
|
|
|
2917
3013
|
fieldObj.setErrorMessage(this.errorMessage);
|
|
2918
3014
|
this.displayValidationServerError();
|
|
2919
3015
|
}
|
|
3016
|
+
fieldObj.validating = false;
|
|
2920
3017
|
});
|
|
2921
3018
|
}
|
|
2922
3019
|
finishFieldValidation(fieldObject, validationResult) {
|