tuain-ng-forms-lib 0.12.21 → 0.12.31
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 +181 -117
- package/bundles/tuain-ng-forms-lib.umd.js.map +1 -1
- package/esm2015/lib/classes/forms/action.js +2 -2
- package/esm2015/lib/classes/forms/element.js +4 -4
- package/esm2015/lib/classes/forms/field.js +143 -112
- package/esm2015/lib/classes/forms/subsection.js +2 -2
- package/esm2015/lib/classes/forms/table/table.js +2 -2
- package/esm2015/lib/components/elements/field.component.js +30 -2
- package/fesm2015/tuain-ng-forms-lib.js +177 -118
- package/fesm2015/tuain-ng-forms-lib.js.map +1 -1
- package/lib/classes/forms/element.d.ts +1 -1
- package/lib/classes/forms/field.d.ts +18 -13
- package/lib/components/elements/field.component.d.ts +16 -0
- package/package.json +1 -1
- package/tuain-ng-forms-lib.metadata.json +1 -1
|
@@ -143,12 +143,40 @@ const DEFAULT_STATE_FLOW = {
|
|
|
143
143
|
]
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
+
const MONITORED_ATTRIBUTES$1 = {
|
|
147
|
+
_maxLength: 'maxLength',
|
|
148
|
+
_onValidation: '_onValidation',
|
|
149
|
+
_fieldValue: 'value',
|
|
150
|
+
captureType: 'captureType',
|
|
151
|
+
fieldTitle: 'fieldTitle',
|
|
152
|
+
fieldType: 'fieldType',
|
|
153
|
+
errorMessage: 'errorMessage',
|
|
154
|
+
errorType: 'errorType',
|
|
155
|
+
errorCode: 'errorCode',
|
|
156
|
+
visibleLabel: 'visibleLabel',
|
|
157
|
+
fieldRequired: 'fieldRequired',
|
|
158
|
+
fieldOptions: 'fieldOptions',
|
|
159
|
+
};
|
|
146
160
|
class FieldComponent {
|
|
147
161
|
constructor() {
|
|
148
162
|
this.componentConstants = Object.assign({}, componentConstants);
|
|
149
163
|
}
|
|
150
164
|
ngOnInit() {
|
|
151
|
-
this.fieldObject
|
|
165
|
+
if (this.fieldObject) {
|
|
166
|
+
// Atributos estáticos
|
|
167
|
+
this.code = this.fieldObject.fieldCode;
|
|
168
|
+
this.fieldInfo = this.fieldObject.fieldInfo;
|
|
169
|
+
this.fieldAlignment = this.fieldObject.fieldAlignment;
|
|
170
|
+
this.tooltipText = this.fieldObject.tooltipText;
|
|
171
|
+
this.fieldObject.widget = this;
|
|
172
|
+
// Atributos dinámicos
|
|
173
|
+
this.fieldObject.attributeChange.subscribe(event => {
|
|
174
|
+
const { name, value } = event;
|
|
175
|
+
if (this[MONITORED_ATTRIBUTES$1[name]]) {
|
|
176
|
+
this[MONITORED_ATTRIBUTES$1[name]] = value;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
152
180
|
this.start();
|
|
153
181
|
}
|
|
154
182
|
start() { }
|
|
@@ -311,9 +339,9 @@ class FormElement {
|
|
|
311
339
|
this.setVisibility((_b = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.visible) !== null && _b !== void 0 ? _b : true);
|
|
312
340
|
this.widget = null;
|
|
313
341
|
}
|
|
314
|
-
isField() { return this.
|
|
315
|
-
isAction() { return this.
|
|
316
|
-
isTable() { return this.
|
|
342
|
+
isField() { return this.elementType === componentConstants.ELEMENTTYPE_FIELD; }
|
|
343
|
+
isAction() { return this.elementType === componentConstants.ELEMENTTYPE_ACTION; }
|
|
344
|
+
isTable() { return this.elementType === componentConstants.ELEMENTTYPE_TABLE; }
|
|
317
345
|
setVisibleStates(newStates) {
|
|
318
346
|
const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
|
|
319
347
|
? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
|
|
@@ -592,7 +620,7 @@ class RecordTable extends FormElement {
|
|
|
592
620
|
this._tableColumnObj = {};
|
|
593
621
|
this._actionsObj = {};
|
|
594
622
|
this.allSelected = false;
|
|
595
|
-
this.
|
|
623
|
+
this.elementType = componentConstants.ELEMENTTYPE_TABLE;
|
|
596
624
|
this.waiting = false;
|
|
597
625
|
this.complexFilter = false;
|
|
598
626
|
this.currentPage = 1;
|
|
@@ -1170,7 +1198,7 @@ class RecordFormSubSection {
|
|
|
1170
1198
|
break;
|
|
1171
1199
|
}
|
|
1172
1200
|
if (elementObject) {
|
|
1173
|
-
elementObject.
|
|
1201
|
+
elementObject.elementType = type;
|
|
1174
1202
|
arrayToAdd.push(elementObject);
|
|
1175
1203
|
this.subSectionElements.push(elementObject);
|
|
1176
1204
|
this.elementsArray[code] = elementObject;
|
|
@@ -1307,7 +1335,7 @@ class FormAction extends FormElement {
|
|
|
1307
1335
|
super(actionDefinition);
|
|
1308
1336
|
this._actionActivated = new Subject();
|
|
1309
1337
|
this.inProgress = false;
|
|
1310
|
-
this.
|
|
1338
|
+
this.elementType = componentConstants.ELEMENTTYPE_ACTION;
|
|
1311
1339
|
this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
|
|
1312
1340
|
this.actionName = actionDefinition.actionTitle;
|
|
1313
1341
|
this.iconName = actionDefinition.iconName || this.actionCode;
|
|
@@ -1349,9 +1377,8 @@ const FIELD_ERR_MSG = 'errorMessage';
|
|
|
1349
1377
|
const FIELD_TOOLTIP = 'tooltipText';
|
|
1350
1378
|
const FIELD_INFO = 'info';
|
|
1351
1379
|
const FIELD_EDITABLE = 'editable';
|
|
1352
|
-
const EMAIL_FORMAT = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$';
|
|
1353
|
-
// Norbey ".+@([\da-z\.-]+)\.([a-z\.]{2,6})"
|
|
1354
1380
|
const FIELD_TYPES = {
|
|
1381
|
+
boolean: 'BOOLEAN',
|
|
1355
1382
|
array: 'ARRAY',
|
|
1356
1383
|
check: 'CHECK',
|
|
1357
1384
|
date: 'DATE',
|
|
@@ -1376,62 +1403,112 @@ const FIELD_TYPES = {
|
|
|
1376
1403
|
email: 'EMAIL',
|
|
1377
1404
|
phone: 'PHONE',
|
|
1378
1405
|
};
|
|
1406
|
+
const FIELD_TYPES_FORMATS = {
|
|
1407
|
+
EMAIL: new RegExp('^\\w+([\\.-]?\\w+)@\\w+([\\.-]?\\w+)(\\.\\w{2,3})+$'),
|
|
1408
|
+
};
|
|
1409
|
+
const INTRINSIC_ERROR_MESSAGES = {
|
|
1410
|
+
EMAIL: `El valor no corresponde a un correo válido`,
|
|
1411
|
+
DEFAULT: `El valor no se ajusta al formato establecido`,
|
|
1412
|
+
};
|
|
1413
|
+
const DEFAULT_ERROR_TYPE = 'error';
|
|
1414
|
+
const DEFAULT_CAPTURE_TYPE = 'INPUT';
|
|
1415
|
+
const DEFAULT_ALIGNMENT = 'left';
|
|
1416
|
+
const MONITORED_ATTRIBUTES = ['_maxLength', '_onValidation', 'captureType', 'fieldTitle', 'fieldType',
|
|
1417
|
+
'errorMessage', 'errorType', 'errorCode', 'visibleLabel', 'fieldRequired', 'fieldOptions', '_fieldValue'];
|
|
1379
1418
|
const STD_MAX_LENGTH = 50;
|
|
1380
1419
|
const BIG_MAX_LENGTH = 500;
|
|
1420
|
+
const fldAttr = {
|
|
1421
|
+
validateOnServer: 'validateOnServer',
|
|
1422
|
+
value: '_fieldValue',
|
|
1423
|
+
minValue: '_minValue',
|
|
1424
|
+
maxValue: '_maxValue',
|
|
1425
|
+
maxLength: '_maxLength',
|
|
1426
|
+
onValidation: '_onValidation',
|
|
1427
|
+
intrinsicErrorMessage: '_intrinsicErrorMessage',
|
|
1428
|
+
code: 'fieldCode',
|
|
1429
|
+
info: 'fieldInfo',
|
|
1430
|
+
defaultValue: 'defaultValue',
|
|
1431
|
+
defaultEditable: 'defaultEditable',
|
|
1432
|
+
customAttributes: 'customAttributes',
|
|
1433
|
+
visibleLabel: 'visibleLabel',
|
|
1434
|
+
required: 'fieldRequired',
|
|
1435
|
+
hasChanged: 'hasChanged',
|
|
1436
|
+
outputOnly: 'outputOnly',
|
|
1437
|
+
captureType: 'captureType',
|
|
1438
|
+
title: 'fieldTitle',
|
|
1439
|
+
type: 'fieldType',
|
|
1440
|
+
alignment: 'fieldAlignment',
|
|
1441
|
+
format: 'fieldFormat',
|
|
1442
|
+
externalValue: 'externalValue',
|
|
1443
|
+
tooltipText: 'tooltipText',
|
|
1444
|
+
errorType: 'errorType',
|
|
1445
|
+
errorCode: 'errorCode',
|
|
1446
|
+
errorMessage: 'errorMessage',
|
|
1447
|
+
options: 'fieldOptions',
|
|
1448
|
+
};
|
|
1381
1449
|
class FieldDescriptor extends FormElement {
|
|
1382
1450
|
constructor(inputFieldReceived) {
|
|
1383
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1451
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1384
1452
|
super(inputFieldReceived);
|
|
1385
1453
|
this._editionFinish = new Subject();
|
|
1386
1454
|
this._editionPartial = new Subject();
|
|
1387
1455
|
this._detailRequest = new Subject();
|
|
1388
|
-
this.
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
this.
|
|
1392
|
-
this.
|
|
1393
|
-
this.captureType =
|
|
1394
|
-
this.
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
this.
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
this.
|
|
1408
|
-
this.
|
|
1409
|
-
this.
|
|
1410
|
-
this.
|
|
1411
|
-
this.
|
|
1412
|
-
this.
|
|
1413
|
-
this.
|
|
1414
|
-
|
|
1415
|
-
|
|
1456
|
+
this._attributeChange = new Subject();
|
|
1457
|
+
this.elementType = componentConstants.ELEMENTTYPE_FIELD;
|
|
1458
|
+
const fld = (inputFieldReceived) ? inputFieldReceived : {};
|
|
1459
|
+
this.setAttr(fldAttr.code, fld.fieldCode);
|
|
1460
|
+
this.setAttr(fldAttr.title, (_a = fld.fieldTitle) !== null && _a !== void 0 ? _a : this.fieldCode);
|
|
1461
|
+
this.setAttr(fldAttr.captureType, (_b = fld.captureType) !== null && _b !== void 0 ? _b : DEFAULT_CAPTURE_TYPE);
|
|
1462
|
+
this.setAttr(fldAttr.defaultValue, (_c = fld.defaultValue) !== null && _c !== void 0 ? _c : null);
|
|
1463
|
+
const defaultTypeAlignment = (tableFieldStyles[this.fieldType] != null)
|
|
1464
|
+
? tableFieldStyles[this.fieldType]['text-align'] : DEFAULT_ALIGNMENT;
|
|
1465
|
+
const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
|
|
1466
|
+
this.setAttr(fldAttr.alignment, fieldAlignment);
|
|
1467
|
+
this.setAttr(fldAttr.info, fld.info || '');
|
|
1468
|
+
let fieldFormat;
|
|
1469
|
+
try {
|
|
1470
|
+
fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
|
|
1471
|
+
}
|
|
1472
|
+
catch (e) {
|
|
1473
|
+
fieldFormat = null;
|
|
1474
|
+
}
|
|
1475
|
+
this.setAttr(fldAttr.format, fieldFormat);
|
|
1476
|
+
this.setAttr(fldAttr.validateOnServer, (_d = fld.serverAction) !== null && _d !== void 0 ? _d : false);
|
|
1477
|
+
this.setAttr(fldAttr.customAttributes, (_e = fld.customAttributes) !== null && _e !== void 0 ? _e : {});
|
|
1478
|
+
this.setAttr(fldAttr.tooltipText, fld.tooltip || '');
|
|
1479
|
+
this.setAttr(fldAttr.defaultEditable, this.enabled);
|
|
1480
|
+
this.setAttr(fldAttr.required, (_f = fld.required) !== null && _f !== void 0 ? _f : false);
|
|
1481
|
+
this.setError(fld.errorCode, fld.errorMessage, (_g = fld.errorType) !== null && _g !== void 0 ? _g : DEFAULT_ERROR_TYPE);
|
|
1482
|
+
this.setAttr(fldAttr.outputOnly, (_h = fld.outputOnly) !== null && _h !== void 0 ? _h : false);
|
|
1483
|
+
const maxLength = (_j = fld.maxLength) !== null && _j !== void 0 ? _j : (this.captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
|
|
1484
|
+
this.setAttr(fldAttr.maxLength, maxLength);
|
|
1485
|
+
this.setAttr(fldAttr.intrinsicErrorMessage, (_k = INTRINSIC_ERROR_MESSAGES[this.fieldType]) !== null && _k !== void 0 ? _k : INTRINSIC_ERROR_MESSAGES.DEFAULT);
|
|
1486
|
+
this.setFieldType(fld.fieldTypeCode);
|
|
1487
|
+
this.setEditable((_l = fld.editable) !== null && _l !== void 0 ? _l : true);
|
|
1488
|
+
this.setVisibleLabel((_m = fld.visibleLabel) !== null && _m !== void 0 ? _m : true);
|
|
1489
|
+
this.setVisibility(fld.visible);
|
|
1490
|
+
this.setFieldOptions(fld.fieldOptions);
|
|
1491
|
+
this.setValue(fld.fieldValue || this.defaultValue || '');
|
|
1416
1492
|
}
|
|
1417
1493
|
get name() { return this.fieldCode; }
|
|
1418
1494
|
get editionFinish() { return this._editionFinish; }
|
|
1495
|
+
get attributeChange() { return this._attributeChange; }
|
|
1419
1496
|
get editionPartial() { return this._editionPartial; }
|
|
1420
1497
|
get detailRequest() { return this._detailRequest; }
|
|
1421
1498
|
get validating() { return this._onValidation; }
|
|
1422
|
-
set validating(isValidating) { this.
|
|
1423
|
-
setIntrinsicErrorMessage(message) { this.
|
|
1499
|
+
set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
|
|
1500
|
+
setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
|
|
1424
1501
|
set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
|
|
1425
1502
|
get fieldValue() { return this.getValue(); }
|
|
1426
1503
|
get required() { return this.fieldRequired; }
|
|
1427
|
-
set required(required) { this.
|
|
1504
|
+
set required(required) { this.setAttr(fldAttr.required, required !== null && required !== void 0 ? required : false); }
|
|
1428
1505
|
get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
|
|
1429
1506
|
set maxLength(requiredMaxLength) {
|
|
1430
1507
|
if (typeof requiredMaxLength === 'string') {
|
|
1431
|
-
this.
|
|
1508
|
+
this.setAttr(fldAttr.maxLength, parseInt(requiredMaxLength, 10));
|
|
1432
1509
|
}
|
|
1433
1510
|
else if (typeof requiredMaxLength === 'number') {
|
|
1434
|
-
this.
|
|
1511
|
+
this.setAttr(fldAttr.maxLength, requiredMaxLength);
|
|
1435
1512
|
}
|
|
1436
1513
|
}
|
|
1437
1514
|
get value() { return this.getValue(); }
|
|
@@ -1441,41 +1518,49 @@ class FieldDescriptor extends FormElement {
|
|
|
1441
1518
|
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
|
|
1442
1519
|
}
|
|
1443
1520
|
notifyEditionFinish() {
|
|
1521
|
+
var _a, _b, _c, _d;
|
|
1444
1522
|
let intrinsicValidation = true;
|
|
1445
|
-
const
|
|
1446
|
-
const fieldFormat = new RegExp(fieldExpression);
|
|
1523
|
+
const fieldDefaultFormat = (_a = FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType]) !== null && _a !== void 0 ? _a : null;
|
|
1447
1524
|
const fieldValue = this.getValue();
|
|
1448
|
-
if (fieldValue && fieldFormat) {
|
|
1449
|
-
intrinsicValidation =
|
|
1525
|
+
if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
|
|
1526
|
+
intrinsicValidation = ((_b = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _b !== void 0 ? _b : true)
|
|
1527
|
+
&& ((_d = (_c = this.fieldFormat) === null || _c === void 0 ? void 0 : _c.test(fieldValue)) !== null && _d !== void 0 ? _d : true);
|
|
1450
1528
|
if (!intrinsicValidation) {
|
|
1451
|
-
|
|
1452
|
-
? `El valor de ${this.fieldTitle} no corresponde a un correo válido`
|
|
1453
|
-
: `El valor de ${this.fieldTitle} no se ajusta al formato establecido`;
|
|
1454
|
-
this.setError('99', message);
|
|
1529
|
+
this.setError('99', this._intrinsicErrorMessage);
|
|
1455
1530
|
}
|
|
1456
1531
|
}
|
|
1457
1532
|
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
|
|
1458
1533
|
}
|
|
1534
|
+
setAttr(name, value) {
|
|
1535
|
+
if (this[name]) {
|
|
1536
|
+
this[name] = value;
|
|
1537
|
+
}
|
|
1538
|
+
if (MONITORED_ATTRIBUTES.includes(name)) {
|
|
1539
|
+
this._attributeChange.next({ name, value });
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1459
1542
|
notifyEditionDetailRequest() {
|
|
1460
1543
|
this._detailRequest.next(this.fieldCode);
|
|
1461
1544
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1545
|
+
setVisibleLabel(visibleLabel) { this.setAttr(fldAttr.visibleLabel, visibleLabel); }
|
|
1546
|
+
showLabel() { this.setVisibleLabel(true); }
|
|
1547
|
+
hideLabel() { this.setVisibleLabel(false); }
|
|
1548
|
+
setChanged(hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); }
|
|
1549
|
+
changed() { this.setChanged(true); }
|
|
1465
1550
|
getRawValue() { return this._fieldValue; }
|
|
1466
|
-
setLabel(label) { this.
|
|
1551
|
+
setLabel(label) { this.setAttr(fldAttr.title, label); }
|
|
1467
1552
|
clean() { this.setValue(this.defaultValue || ''); }
|
|
1468
1553
|
get backend() { return this.validateOnServer; }
|
|
1469
|
-
setVisibleLabel(visibleLabel) { this.visibleLabel = visibleLabel; }
|
|
1470
1554
|
setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
this.errorCode
|
|
1474
|
-
this.
|
|
1555
|
+
hasError() { return this.errorCode !== '00'; }
|
|
1556
|
+
setError(code, message, type = DEFAULT_ERROR_TYPE) {
|
|
1557
|
+
this.setAttr(fldAttr.errorCode, code !== null && code !== void 0 ? code : '00');
|
|
1558
|
+
this.setAttr(fldAttr.errorType, (this.errorCode === '00') ? '' : type);
|
|
1559
|
+
this.setAttr(fldAttr.errorMessage, message !== null && message !== void 0 ? message : '');
|
|
1475
1560
|
}
|
|
1476
1561
|
getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
|
|
1477
1562
|
get error() { return this.getError(); }
|
|
1478
|
-
set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); }
|
|
1563
|
+
set error(errorObj) { var _a; this.setError(errorObj.code, errorObj.message, (_a = errorObj.type) !== null && _a !== void 0 ? _a : DEFAULT_ERROR_TYPE); }
|
|
1479
1564
|
getErrorCode() { return this.getError().code; }
|
|
1480
1565
|
setErrorCode(code) { this.setError(code, this.errorMessage); }
|
|
1481
1566
|
getErrorMessage() { return this.getError().message; }
|
|
@@ -1508,68 +1593,39 @@ class FieldDescriptor extends FormElement {
|
|
|
1508
1593
|
}
|
|
1509
1594
|
updateFromServer(fld) {
|
|
1510
1595
|
var _a;
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
this.
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
(this.
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
(this.
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
(this.
|
|
1528
|
-
|
|
1529
|
-
if (FIELD_INFO in fld) {
|
|
1530
|
-
(this.fieldInfo = fld.info);
|
|
1531
|
-
}
|
|
1532
|
-
if (FIELD_EDITABLE in fld) {
|
|
1533
|
-
this.setEditable(fld.editable);
|
|
1534
|
-
}
|
|
1535
|
-
if (FIELD_TITLE in fld) {
|
|
1536
|
-
this.setLabel(fld.fieldTitle.toString());
|
|
1537
|
-
}
|
|
1538
|
-
if (FIELD_VALUE in fld) {
|
|
1539
|
-
this.hasChanged = false;
|
|
1540
|
-
this.setValue(fld.fieldValue);
|
|
1541
|
-
}
|
|
1542
|
-
if (FIELD_OPTIONS in fld) {
|
|
1543
|
-
this.setFieldOptions(fld.fieldOptions);
|
|
1544
|
-
}
|
|
1545
|
-
if (FIELD_CAPTURE_TYPE in fld) {
|
|
1546
|
-
this.captureType = fld.captureType || 'INPUT';
|
|
1547
|
-
}
|
|
1548
|
-
if (FIELD_TYPE in fld) {
|
|
1549
|
-
this.setFieldType(fld.fieldTypeCode);
|
|
1550
|
-
}
|
|
1551
|
-
if (FIELD_MAX_LENGTH in fld) {
|
|
1552
|
-
this.maxLength = fld.maxLength;
|
|
1596
|
+
const fieldKeys = Object.keys(fld);
|
|
1597
|
+
for (let index = 0; index < fieldKeys.length; index++) {
|
|
1598
|
+
const attrName = fieldKeys[index];
|
|
1599
|
+
const attrValue = fld[attrName];
|
|
1600
|
+
(attrName === FIELD_VISIBLE) && this.setVisibility(attrValue);
|
|
1601
|
+
(attrName === FIELD_LABEL_VISIBLE) && this.setVisibleLabel(fld.visibleLabel);
|
|
1602
|
+
(attrName === FIELD_REQUIRED) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
|
|
1603
|
+
(attrName === FIELD_ERR_CODE) && this.setAttr(fldAttr.errorCode, fld.errorCode);
|
|
1604
|
+
(attrName === FIELD_ERR_MSG) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
|
|
1605
|
+
(attrName === FIELD_TOOLTIP) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
|
|
1606
|
+
(attrName === FIELD_INFO) && this.setAttr(fldAttr.info, fld.info);
|
|
1607
|
+
(attrName === FIELD_EDITABLE) && this.setEditable(fld.editable);
|
|
1608
|
+
(attrName === FIELD_TITLE) && this.setLabel(fld.fieldTitle.toString());
|
|
1609
|
+
(attrName === FIELD_VALUE) && (this.setValue(fld._fieldValue) && this.setChanged(false));
|
|
1610
|
+
(attrName === FIELD_OPTIONS) && this.setFieldOptions(fld.fieldOptions);
|
|
1611
|
+
(attrName === FIELD_CAPTURE_TYPE) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
|
|
1612
|
+
(attrName === FIELD_TYPE) && this.setFieldType(fld.fieldTypeCode);
|
|
1613
|
+
(attrName === FIELD_MAX_LENGTH) && this.setAttr(fldAttr.maxLength, fld.maxLength);
|
|
1553
1614
|
}
|
|
1554
1615
|
}
|
|
1555
1616
|
setFieldType(inputFieldType) {
|
|
1556
|
-
this.
|
|
1557
|
-
/**
|
|
1558
|
-
* Se elimina la validación de que sea un tipo conocido
|
|
1559
|
-
* this.fieldType = (inputFieldType && FIELDTYPES.includes(inputFieldType))
|
|
1560
|
-
* ? inputFieldType : componentConstants.FIELDTYPE_TEXT;
|
|
1561
|
-
*/
|
|
1617
|
+
this.setAttr(fldAttr.type, inputFieldType);
|
|
1562
1618
|
}
|
|
1563
1619
|
format() {
|
|
1564
1620
|
if (this.fieldType === componentConstants.FIELDTYPE_CURRENCY) {
|
|
1565
|
-
this.
|
|
1621
|
+
this.setAttr(fldAttr.value, formatCurrency(this._fieldValue));
|
|
1566
1622
|
}
|
|
1567
1623
|
}
|
|
1568
1624
|
setMinValue(minValue) {
|
|
1569
1625
|
var _a, _b, _c;
|
|
1570
1626
|
if (this.fieldType === componentConstants.FIELDTYPE_DATE
|
|
1571
1627
|
&& ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
|
|
1572
|
-
this.
|
|
1628
|
+
this.setAttr(fldAttr.minValue, minValue);
|
|
1573
1629
|
if (!minValue) {
|
|
1574
1630
|
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
|
|
1575
1631
|
}
|
|
@@ -1583,7 +1639,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1583
1639
|
var _a, _b, _c;
|
|
1584
1640
|
if (this.fieldType === componentConstants.FIELDTYPE_DATE
|
|
1585
1641
|
&& ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
|
|
1586
|
-
this.
|
|
1642
|
+
this.setAttr(fldAttr.maxValue, maxValue);
|
|
1587
1643
|
if (!maxValue) {
|
|
1588
1644
|
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
|
|
1589
1645
|
}
|
|
@@ -1603,21 +1659,23 @@ class FieldDescriptor extends FormElement {
|
|
|
1603
1659
|
|| !Array.isArray(newOptions)) {
|
|
1604
1660
|
return;
|
|
1605
1661
|
}
|
|
1606
|
-
|
|
1662
|
+
let fieldOptions = newOptions.map(option => {
|
|
1607
1663
|
if (option.text !== undefined && option.text !== null
|
|
1608
1664
|
&& option.value !== undefined && option.value !== null) {
|
|
1609
1665
|
return { fieldOptionValue: option.text, fieldOptionId: option.value };
|
|
1610
1666
|
}
|
|
1611
1667
|
return Object.assign({}, option);
|
|
1612
1668
|
});
|
|
1613
|
-
|
|
1669
|
+
fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
|
|
1614
1670
|
&& fieldOptions.length > 0) ? fieldOptions : [];
|
|
1671
|
+
this.setAttr(fldAttr.options, fieldOptions);
|
|
1615
1672
|
if (this.fieldType === componentConstants.FIELDTYPE_ARRAY && this.widget) {
|
|
1616
1673
|
return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
|
|
1617
1674
|
}
|
|
1618
1675
|
if (this._fieldValue) {
|
|
1619
1676
|
if (this.fieldType === componentConstants.FIELDTYPE_ARRAY && Array.isArray(this._fieldValue)) {
|
|
1620
|
-
|
|
1677
|
+
const fieldValue = (_b = this._fieldValue) === null || _b === void 0 ? void 0 : _b.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
|
|
1678
|
+
this.setAttr(fldAttr.value, fieldValue);
|
|
1621
1679
|
}
|
|
1622
1680
|
else {
|
|
1623
1681
|
const valInOptions = this.fieldOptions
|
|
@@ -1637,7 +1695,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1637
1695
|
setValue(newValue, widgetUpdate = true) {
|
|
1638
1696
|
var _a;
|
|
1639
1697
|
if (typeof newValue === UNDEFINED || newValue === null) {
|
|
1640
|
-
return;
|
|
1698
|
+
return true;
|
|
1641
1699
|
}
|
|
1642
1700
|
let newFinalValue;
|
|
1643
1701
|
switch (this.fieldType) {
|
|
@@ -1677,9 +1735,10 @@ class FieldDescriptor extends FormElement {
|
|
|
1677
1735
|
break;
|
|
1678
1736
|
}
|
|
1679
1737
|
if (this._fieldValue !== newFinalValue) {
|
|
1680
|
-
this.
|
|
1681
|
-
this.
|
|
1738
|
+
this.setChanged(true);
|
|
1739
|
+
this.setAttr(fldAttr.value, newFinalValue);
|
|
1682
1740
|
}
|
|
1741
|
+
return true;
|
|
1683
1742
|
}
|
|
1684
1743
|
}
|
|
1685
1744
|
|