tuain-ng-forms-lib 0.12.20 → 0.12.30
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 +286 -111
- 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 +204 -100
- package/esm2015/lib/classes/forms/form.js +9 -1
- 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/esm2015/lib/components/forms/basic-form.js +16 -6
- package/fesm2015/tuain-ng-forms-lib.js +261 -111
- 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 +44 -16
- package/lib/classes/forms/form.d.ts +2 -0
- package/lib/components/elements/field.component.d.ts +16 -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
|
@@ -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.fieldCode = 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,76 +1377,206 @@ const FIELD_ERR_MSG = 'errorMessage';
|
|
|
1349
1377
|
const FIELD_TOOLTIP = 'tooltipText';
|
|
1350
1378
|
const FIELD_INFO = 'info';
|
|
1351
1379
|
const FIELD_EDITABLE = 'editable';
|
|
1380
|
+
const FIELD_TYPES = {
|
|
1381
|
+
boolean: 'BOOLEAN',
|
|
1382
|
+
array: 'ARRAY',
|
|
1383
|
+
check: 'CHECK',
|
|
1384
|
+
date: 'DATE',
|
|
1385
|
+
daterange: 'DATERANGE',
|
|
1386
|
+
time: 'TIME',
|
|
1387
|
+
timerange: 'TIMERANGE',
|
|
1388
|
+
map: 'MAP',
|
|
1389
|
+
number: 'NUMBER',
|
|
1390
|
+
decimal: 'DECIMAL',
|
|
1391
|
+
currency: 'CURRENCY',
|
|
1392
|
+
select: 'SELECT',
|
|
1393
|
+
typeahead: 'TYPEAHEAD',
|
|
1394
|
+
text: 'TEXT',
|
|
1395
|
+
password: 'PASSWORD',
|
|
1396
|
+
label: 'LABEL',
|
|
1397
|
+
html: 'HTML',
|
|
1398
|
+
title: 'TITLE',
|
|
1399
|
+
message: 'MESSAGE',
|
|
1400
|
+
link: 'LINK',
|
|
1401
|
+
warning: 'WARNING',
|
|
1402
|
+
avatar: 'AVATAR',
|
|
1403
|
+
email: 'EMAIL',
|
|
1404
|
+
phone: 'PHONE',
|
|
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'];
|
|
1352
1418
|
const STD_MAX_LENGTH = 50;
|
|
1353
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
|
+
};
|
|
1354
1449
|
class FieldDescriptor extends FormElement {
|
|
1355
1450
|
constructor(inputFieldReceived) {
|
|
1356
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1451
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1357
1452
|
super(inputFieldReceived);
|
|
1358
1453
|
this._editionFinish = new Subject();
|
|
1359
1454
|
this._editionPartial = new Subject();
|
|
1360
1455
|
this._detailRequest = new Subject();
|
|
1361
|
-
this.
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
this.
|
|
1365
|
-
this.
|
|
1366
|
-
this.captureType =
|
|
1367
|
-
this.
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
this.
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
this.
|
|
1381
|
-
this.
|
|
1382
|
-
this.
|
|
1383
|
-
this.
|
|
1384
|
-
this.
|
|
1385
|
-
this.
|
|
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 || '');
|
|
1386
1492
|
}
|
|
1387
1493
|
get name() { return this.fieldCode; }
|
|
1388
1494
|
get editionFinish() { return this._editionFinish; }
|
|
1495
|
+
get attributeChange() { return this._attributeChange; }
|
|
1389
1496
|
get editionPartial() { return this._editionPartial; }
|
|
1390
1497
|
get detailRequest() { return this._detailRequest; }
|
|
1498
|
+
get validating() { return this._onValidation; }
|
|
1499
|
+
set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
|
|
1500
|
+
setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
|
|
1501
|
+
set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
|
|
1391
1502
|
get fieldValue() { return this.getValue(); }
|
|
1392
1503
|
get required() { return this.fieldRequired; }
|
|
1393
|
-
set required(required) { this.
|
|
1504
|
+
set required(required) { this.setAttr(fldAttr.required, required !== null && required !== void 0 ? required : false); }
|
|
1394
1505
|
get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
|
|
1395
1506
|
set maxLength(requiredMaxLength) {
|
|
1396
1507
|
if (typeof requiredMaxLength === 'string') {
|
|
1397
|
-
this.
|
|
1508
|
+
this.setAttr(fldAttr.maxLength, parseInt(requiredMaxLength, 10));
|
|
1398
1509
|
}
|
|
1399
1510
|
else if (typeof requiredMaxLength === 'number') {
|
|
1400
|
-
this.
|
|
1511
|
+
this.setAttr(fldAttr.maxLength, requiredMaxLength);
|
|
1401
1512
|
}
|
|
1402
1513
|
}
|
|
1403
1514
|
get value() { return this.getValue(); }
|
|
1404
1515
|
set value(newValue) { this.setValue(newValue); }
|
|
1405
|
-
notifyEditionPartial() {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1516
|
+
notifyEditionPartial() {
|
|
1517
|
+
const intrinsicValidation = true;
|
|
1518
|
+
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
|
|
1519
|
+
}
|
|
1520
|
+
notifyEditionFinish() {
|
|
1521
|
+
var _a, _b, _c, _d;
|
|
1522
|
+
let intrinsicValidation = true;
|
|
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;
|
|
1524
|
+
const fieldValue = this.getValue();
|
|
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);
|
|
1528
|
+
if (!intrinsicValidation) {
|
|
1529
|
+
this.setError('99', this._intrinsicErrorMessage);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
|
|
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
|
+
}
|
|
1542
|
+
notifyEditionDetailRequest() {
|
|
1543
|
+
this._detailRequest.next(this.fieldCode);
|
|
1544
|
+
}
|
|
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); }
|
|
1411
1550
|
getRawValue() { return this._fieldValue; }
|
|
1412
|
-
setLabel(label) { this.
|
|
1551
|
+
setLabel(label) { this.setAttr(fldAttr.title, label); }
|
|
1413
1552
|
clean() { this.setValue(this.defaultValue || ''); }
|
|
1414
1553
|
get backend() { return this.validateOnServer; }
|
|
1415
|
-
setVisibleLabel(visibleLabel) { this.visibleLabel = visibleLabel; }
|
|
1416
1554
|
setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
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 : '');
|
|
1560
|
+
}
|
|
1561
|
+
getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
|
|
1562
|
+
get error() { return this.getError(); }
|
|
1563
|
+
set error(errorObj) { var _a; this.setError(errorObj.code, errorObj.message, (_a = errorObj.type) !== null && _a !== void 0 ? _a : DEFAULT_ERROR_TYPE); }
|
|
1564
|
+
getErrorCode() { return this.getError().code; }
|
|
1565
|
+
setErrorCode(code) { this.setError(code, this.errorMessage); }
|
|
1566
|
+
getErrorMessage() { return this.getError().message; }
|
|
1567
|
+
setErrorMessage(msg) { this.setError(this.errorCode, msg); }
|
|
1568
|
+
isEmpty() {
|
|
1569
|
+
const fieldCurrentValue = this.getValue();
|
|
1570
|
+
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
1571
|
+
return true;
|
|
1572
|
+
}
|
|
1573
|
+
if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
|
|
1574
|
+
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
1575
|
+
return true;
|
|
1576
|
+
}
|
|
1577
|
+
;
|
|
1578
|
+
return fieldCurrentValue === '';
|
|
1579
|
+
}
|
|
1422
1580
|
getValue() {
|
|
1423
1581
|
var _a;
|
|
1424
1582
|
switch (this.fieldType) {
|
|
@@ -1435,68 +1593,39 @@ class FieldDescriptor extends FormElement {
|
|
|
1435
1593
|
}
|
|
1436
1594
|
updateFromServer(fld) {
|
|
1437
1595
|
var _a;
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
this.
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
(this.
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
(this.
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
(this.
|
|
1455
|
-
|
|
1456
|
-
if (FIELD_INFO in fld) {
|
|
1457
|
-
(this.fieldInfo = fld.info);
|
|
1458
|
-
}
|
|
1459
|
-
if (FIELD_EDITABLE in fld) {
|
|
1460
|
-
this.setEditable(fld.editable);
|
|
1461
|
-
}
|
|
1462
|
-
if (FIELD_TITLE in fld) {
|
|
1463
|
-
this.setLabel(fld.fieldTitle.toString());
|
|
1464
|
-
}
|
|
1465
|
-
if (FIELD_VALUE in fld) {
|
|
1466
|
-
this.hasChanged = false;
|
|
1467
|
-
this.setValue(fld.fieldValue);
|
|
1468
|
-
}
|
|
1469
|
-
if (FIELD_OPTIONS in fld) {
|
|
1470
|
-
this.setFieldOptions(fld.fieldOptions);
|
|
1471
|
-
}
|
|
1472
|
-
if (FIELD_CAPTURE_TYPE in fld) {
|
|
1473
|
-
this.captureType = fld.captureType || 'INPUT';
|
|
1474
|
-
}
|
|
1475
|
-
if (FIELD_TYPE in fld) {
|
|
1476
|
-
this.setFieldType(fld.fieldTypeCode);
|
|
1477
|
-
}
|
|
1478
|
-
if (FIELD_MAX_LENGTH in fld) {
|
|
1479
|
-
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);
|
|
1480
1614
|
}
|
|
1481
1615
|
}
|
|
1482
1616
|
setFieldType(inputFieldType) {
|
|
1483
|
-
this.
|
|
1484
|
-
/**
|
|
1485
|
-
* Se elimina la validación de que sea un tipo conocido
|
|
1486
|
-
* this.fieldType = (inputFieldType && FIELDTYPES.includes(inputFieldType))
|
|
1487
|
-
* ? inputFieldType : componentConstants.FIELDTYPE_TEXT;
|
|
1488
|
-
*/
|
|
1617
|
+
this.setAttr(fldAttr.type, inputFieldType);
|
|
1489
1618
|
}
|
|
1490
1619
|
format() {
|
|
1491
1620
|
if (this.fieldType === componentConstants.FIELDTYPE_CURRENCY) {
|
|
1492
|
-
this.
|
|
1621
|
+
this.setAttr(fldAttr.value, formatCurrency(this._fieldValue));
|
|
1493
1622
|
}
|
|
1494
1623
|
}
|
|
1495
1624
|
setMinValue(minValue) {
|
|
1496
1625
|
var _a, _b, _c;
|
|
1497
1626
|
if (this.fieldType === componentConstants.FIELDTYPE_DATE
|
|
1498
1627
|
&& ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
|
|
1499
|
-
this.
|
|
1628
|
+
this.setAttr(fldAttr.minValue, minValue);
|
|
1500
1629
|
if (!minValue) {
|
|
1501
1630
|
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
|
|
1502
1631
|
}
|
|
@@ -1510,7 +1639,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1510
1639
|
var _a, _b, _c;
|
|
1511
1640
|
if (this.fieldType === componentConstants.FIELDTYPE_DATE
|
|
1512
1641
|
&& ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
|
|
1513
|
-
this.
|
|
1642
|
+
this.setAttr(fldAttr.maxValue, maxValue);
|
|
1514
1643
|
if (!maxValue) {
|
|
1515
1644
|
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
|
|
1516
1645
|
}
|
|
@@ -1530,21 +1659,23 @@ class FieldDescriptor extends FormElement {
|
|
|
1530
1659
|
|| !Array.isArray(newOptions)) {
|
|
1531
1660
|
return;
|
|
1532
1661
|
}
|
|
1533
|
-
|
|
1662
|
+
let fieldOptions = newOptions.map(option => {
|
|
1534
1663
|
if (option.text !== undefined && option.text !== null
|
|
1535
1664
|
&& option.value !== undefined && option.value !== null) {
|
|
1536
1665
|
return { fieldOptionValue: option.text, fieldOptionId: option.value };
|
|
1537
1666
|
}
|
|
1538
1667
|
return Object.assign({}, option);
|
|
1539
1668
|
});
|
|
1540
|
-
|
|
1669
|
+
fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
|
|
1541
1670
|
&& fieldOptions.length > 0) ? fieldOptions : [];
|
|
1671
|
+
this.setAttr(fldAttr.options, fieldOptions);
|
|
1542
1672
|
if (this.fieldType === componentConstants.FIELDTYPE_ARRAY && this.widget) {
|
|
1543
1673
|
return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
|
|
1544
1674
|
}
|
|
1545
1675
|
if (this._fieldValue) {
|
|
1546
1676
|
if (this.fieldType === componentConstants.FIELDTYPE_ARRAY && Array.isArray(this._fieldValue)) {
|
|
1547
|
-
|
|
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);
|
|
1548
1679
|
}
|
|
1549
1680
|
else {
|
|
1550
1681
|
const valInOptions = this.fieldOptions
|
|
@@ -1564,7 +1695,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1564
1695
|
setValue(newValue, widgetUpdate = true) {
|
|
1565
1696
|
var _a;
|
|
1566
1697
|
if (typeof newValue === UNDEFINED || newValue === null) {
|
|
1567
|
-
return;
|
|
1698
|
+
return true;
|
|
1568
1699
|
}
|
|
1569
1700
|
let newFinalValue;
|
|
1570
1701
|
switch (this.fieldType) {
|
|
@@ -1604,9 +1735,10 @@ class FieldDescriptor extends FormElement {
|
|
|
1604
1735
|
break;
|
|
1605
1736
|
}
|
|
1606
1737
|
if (this._fieldValue !== newFinalValue) {
|
|
1607
|
-
this.
|
|
1608
|
-
this.
|
|
1738
|
+
this.setChanged(true);
|
|
1739
|
+
this.setAttr(fldAttr.value, newFinalValue);
|
|
1609
1740
|
}
|
|
1741
|
+
return true;
|
|
1610
1742
|
}
|
|
1611
1743
|
}
|
|
1612
1744
|
|
|
@@ -1976,6 +2108,14 @@ class FormStructureAndData {
|
|
|
1976
2108
|
const fieldObject = this.getFieldObject(fieldCode);
|
|
1977
2109
|
return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
|
|
1978
2110
|
}
|
|
2111
|
+
setFieldError(code, message, type = 'error') {
|
|
2112
|
+
const fieldObject = this.getFieldObject(code);
|
|
2113
|
+
return (fieldObject) ? fieldObject.setError(code, message, type) : null;
|
|
2114
|
+
}
|
|
2115
|
+
setFieldIntrinsicErrorMessage(code, message) {
|
|
2116
|
+
const fieldObject = this.getFieldObject(code);
|
|
2117
|
+
return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
|
|
2118
|
+
}
|
|
1979
2119
|
setFieldRequired(fieldCode, required) {
|
|
1980
2120
|
const fieldObject = this.getFieldObject(fieldCode);
|
|
1981
2121
|
return (fieldObject) ? fieldObject.required = required : null;
|
|
@@ -2356,6 +2496,8 @@ class BasicFormComponent {
|
|
|
2356
2496
|
setFieldValue(fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); }
|
|
2357
2497
|
setFieldRequired(fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); }
|
|
2358
2498
|
setFieldErrorMessage(fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); }
|
|
2499
|
+
setFieldError(code, message, type = 'error') { return this.formStructure.setFieldError(code, message, type); }
|
|
2500
|
+
setFieldIntrinsicErrorMessage(code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); }
|
|
2359
2501
|
setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute) {
|
|
2360
2502
|
return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
|
|
2361
2503
|
}
|
|
@@ -2548,8 +2690,14 @@ class BasicFormComponent {
|
|
|
2548
2690
|
const formFields = this.formStructure.getFields();
|
|
2549
2691
|
if (Array.isArray(formFields)) {
|
|
2550
2692
|
formFields.forEach(field => {
|
|
2551
|
-
field.editionFinish.subscribe(
|
|
2552
|
-
|
|
2693
|
+
field.editionFinish.subscribe(event => {
|
|
2694
|
+
const { code, intrinsicValidation } = event;
|
|
2695
|
+
this.startFieldValidation(code, intrinsicValidation);
|
|
2696
|
+
});
|
|
2697
|
+
field.editionPartial.subscribe(event => {
|
|
2698
|
+
const { code, intrinsicValidation } = event;
|
|
2699
|
+
this.startFieldInputValidation(code, intrinsicValidation);
|
|
2700
|
+
});
|
|
2553
2701
|
field.detailRequest.subscribe(code => this.showFieldInfo(code));
|
|
2554
2702
|
});
|
|
2555
2703
|
}
|
|
@@ -2860,7 +3008,7 @@ class BasicFormComponent {
|
|
|
2860
3008
|
this.fieldValidationsFinish[fieldCode].push(callbackMethod);
|
|
2861
3009
|
});
|
|
2862
3010
|
}
|
|
2863
|
-
startFieldInputValidation(fieldCode) {
|
|
3011
|
+
startFieldInputValidation(fieldCode, intrinsicValidation = true) {
|
|
2864
3012
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2865
3013
|
const fieldToValidate = this.getFieldObject(fieldCode);
|
|
2866
3014
|
if (!fieldToValidate) {
|
|
@@ -2879,10 +3027,10 @@ class BasicFormComponent {
|
|
|
2879
3027
|
}
|
|
2880
3028
|
});
|
|
2881
3029
|
}
|
|
2882
|
-
startFieldValidation(fieldCode) {
|
|
3030
|
+
startFieldValidation(fieldCode, intrinsicValidation = true) {
|
|
2883
3031
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2884
3032
|
const fieldToValidate = this.getField(fieldCode);
|
|
2885
|
-
if (!fieldToValidate) {
|
|
3033
|
+
if (!fieldToValidate || !intrinsicValidation) {
|
|
2886
3034
|
return;
|
|
2887
3035
|
}
|
|
2888
3036
|
fieldToValidate.setErrorMessage('');
|
|
@@ -2910,6 +3058,7 @@ class BasicFormComponent {
|
|
|
2910
3058
|
let finish = true;
|
|
2911
3059
|
let validationResult = null;
|
|
2912
3060
|
if (fieldObj.backend) {
|
|
3061
|
+
fieldObj.validating = true;
|
|
2913
3062
|
validationResult = yield this
|
|
2914
3063
|
.requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode);
|
|
2915
3064
|
finish = !this.errorOccured();
|
|
@@ -2922,6 +3071,7 @@ class BasicFormComponent {
|
|
|
2922
3071
|
fieldObj.setErrorMessage(this.errorMessage);
|
|
2923
3072
|
this.displayValidationServerError();
|
|
2924
3073
|
}
|
|
3074
|
+
fieldObj.validating = false;
|
|
2925
3075
|
});
|
|
2926
3076
|
}
|
|
2927
3077
|
finishFieldValidation(fieldObject, validationResult) {
|