tuain-ng-forms-lib 12.0.35 → 12.0.41

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.
@@ -60,7 +60,8 @@ ActionComponent.propDecorators = {
60
60
  showLabel: [{ type: Input }]
61
61
  };
62
62
 
63
- const VALUE = '';
63
+ const VALUE = 'value';
64
+ const FOCUS = 'focus';
64
65
  class FieldComponent {
65
66
  ngOnInit() {
66
67
  var _a, _b;
@@ -69,29 +70,35 @@ class FieldComponent {
69
70
  // Inicialización
70
71
  const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
71
72
  for (let index = 0; index < mapping.length; index++) {
72
- const [fieldAttr, compAttr1] = mapping[index];
73
+ const [fieldAttr1, compAttr1] = mapping[index];
73
74
  const compAttr = compAttr1.toString();
74
- if (compAttr === VALUE) {
75
- this.updateValue();
76
- }
77
- else {
78
- this[compAttr] = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
79
- }
75
+ const fieldAttr = fieldAttr1.toString();
76
+ const attributeValue = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr];
77
+ this.dafaultProcessFieldChange(compAttr, attributeValue);
78
+ this.processFieldChange(compAttr, attributeValue);
80
79
  }
81
80
  // Subscripción a cambios en atributos
82
81
  this.field.attributeChange.subscribe(event => {
83
82
  const { name: fieldAttr, value } = event;
84
83
  const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
85
- if (compAttr === VALUE) {
86
- this.updateValue();
87
- }
88
- else {
89
- this[compAttr] = value;
90
- }
84
+ this.dafaultProcessFieldChange(compAttr, value);
85
+ this.processFieldChange(compAttr, value);
91
86
  });
92
87
  }
93
88
  this.start();
94
89
  }
90
+ dafaultProcessFieldChange(attribute, value) {
91
+ if (attribute === VALUE) {
92
+ this.updateValue();
93
+ }
94
+ else if (attribute === FOCUS) {
95
+ this.focus();
96
+ }
97
+ else {
98
+ this[attribute] = value;
99
+ }
100
+ }
101
+ processFieldChange(attribute, value) { }
95
102
  start() { }
96
103
  focus() { }
97
104
  updateObject() {
@@ -294,7 +301,6 @@ class FormElement {
294
301
  this._visibleForced = false;
295
302
  this.disabled = (_a = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.disabled) !== null && _a !== void 0 ? _a : false;
296
303
  this.setVisibility((_b = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.visible) !== null && _b !== void 0 ? _b : true);
297
- this.widget = null;
298
304
  this.customAttributes = (_c = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.customAttributes) !== null && _c !== void 0 ? _c : {};
299
305
  }
300
306
  getCustomAttribute(name) { var _a, _b; return (_b = (_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; }
@@ -524,9 +530,9 @@ class RecordTable extends FormElement {
524
530
  this._selectionActionTrigger = new Subject();
525
531
  this._getDataTrigger = new Subject();
526
532
  this._attributeChange = new Subject();
527
- this.tableRecordObj = {};
528
533
  this._tableColumnObj = {};
529
534
  this._actionsObj = {};
535
+ this.tableRecordObj = {};
530
536
  this.allSelected = false;
531
537
  this.elementType = elementTypes.table;
532
538
  this.waiting = false;
@@ -995,7 +1001,6 @@ class LibTableComponent {
995
1001
  this.tableFieldStyles = this.formConfig.tableFieldStyles;
996
1002
  this.selectable = this.table.selectable;
997
1003
  this.hasActions = this.table.hasActions;
998
- this.table.widget = this;
999
1004
  this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
1000
1005
  this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
1001
1006
  this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
@@ -1151,6 +1156,7 @@ const fldAttr = {
1151
1156
  maxValue: '_maxValue',
1152
1157
  maxLength: '_maxLength',
1153
1158
  onValidation: '_onValidation',
1159
+ focus: 'focus',
1154
1160
  intrinsicErrorMessage: '_intrinsicErrorMessage',
1155
1161
  code: 'fieldCode',
1156
1162
  info: 'fieldInfo',
@@ -1223,6 +1229,7 @@ class FieldDescriptor extends FormElement {
1223
1229
  get info() { return this.fieldInfo; }
1224
1230
  get validating() { return this._onValidation; }
1225
1231
  set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
1232
+ focus() { this.setAttr(fldAttr.focus, true); }
1226
1233
  setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
1227
1234
  set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
1228
1235
  get fieldValue() { return this.getValue(); }
@@ -1257,6 +1264,14 @@ class FieldDescriptor extends FormElement {
1257
1264
  this.setError('99', this._intrinsicErrorMessage);
1258
1265
  }
1259
1266
  }
1267
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
1268
+ intrinsicValidation = false;
1269
+ this.setError('99', 'Campo con valor inferior al mínimo');
1270
+ }
1271
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
1272
+ intrinsicValidation = false;
1273
+ this.setError('99', 'Campo con valor superior al máximo');
1274
+ }
1260
1275
  this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
1261
1276
  }
1262
1277
  setAttr(name, value) {
@@ -1311,6 +1326,10 @@ class FieldDescriptor extends FormElement {
1311
1326
  }
1312
1327
  return this._value;
1313
1328
  }
1329
+ getOptionText() {
1330
+ var _a, _b;
1331
+ (_b = (_a = this.fieldOptions.find(item => item.fieldOptionId === this._value)) === null || _a === void 0 ? void 0 : _a.fieldOptionValue) !== null && _b !== void 0 ? _b : null;
1332
+ }
1314
1333
  updateFromServer(fld) {
1315
1334
  var _a;
1316
1335
  const fieldKeys = Object.keys(fld);
@@ -1336,39 +1355,25 @@ class FieldDescriptor extends FormElement {
1336
1355
  setFieldType(inputFieldType) {
1337
1356
  this.setAttr(fldAttr.type, inputFieldType);
1338
1357
  }
1339
- setMinValue(minValue) {
1340
- var _a, _b, _c;
1341
- if (this.fieldType === this._formConfig.fieldTypes.date
1342
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
1343
- this.setAttr(fldAttr.minValue, minValue);
1344
- if (!minValue) {
1345
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
1346
- }
1347
- else {
1348
- const minDate = new Date(minValue);
1349
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
1350
- }
1358
+ setMinValue(inputMinValue) {
1359
+ let minValue = inputMinValue;
1360
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1361
+ minValue = new Date(minValue);
1351
1362
  }
1363
+ this.setAttr(fldAttr.minValue, minValue);
1352
1364
  }
1353
- setMaxValue(maxValue) {
1354
- var _a, _b, _c;
1355
- if (this.fieldType === this._formConfig.fieldTypes.date
1356
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
1357
- this.setAttr(fldAttr.maxValue, maxValue);
1358
- if (!maxValue) {
1359
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
1360
- }
1361
- else {
1362
- const maxDate = new Date(maxValue);
1363
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
1364
- }
1365
+ setMaxValue(inputMaxValue) {
1366
+ let maxValue = inputMaxValue;
1367
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1368
+ maxValue = new Date(maxValue);
1365
1369
  }
1370
+ this.setAttr(fldAttr.maxValue, maxValue);
1366
1371
  }
1367
1372
  getFieldOptions() {
1368
1373
  return JSON.parse(JSON.stringify(this.fieldOptions));
1369
1374
  }
1370
1375
  setFieldOptions(newOptions) {
1371
- var _a, _b, _c, _d;
1376
+ var _a;
1372
1377
  if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1373
1378
  || typeof newOptions === UNDEFINED || !newOptions
1374
1379
  || !Array.isArray(newOptions)) {
@@ -1384,12 +1389,9 @@ class FieldDescriptor extends FormElement {
1384
1389
  fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
1385
1390
  && fieldOptions.length > 0) ? fieldOptions : [];
1386
1391
  this.setAttr(fldAttr.options, fieldOptions);
1387
- if (this.fieldType === this._formConfig.fieldTypes.array && this.widget) {
1388
- return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
1389
- }
1390
1392
  if (this._value) {
1391
1393
  if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
1392
- const fieldValue = (_b = this._value) === null || _b === void 0 ? void 0 : _b.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1394
+ const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1393
1395
  this.setAttr(fldAttr.value, fieldValue);
1394
1396
  }
1395
1397
  else {
@@ -1402,56 +1404,40 @@ class FieldDescriptor extends FormElement {
1402
1404
  }
1403
1405
  if (this.fieldRequired && this.fieldOptions.length === 1) {
1404
1406
  this.setValue(this.fieldOptions[0].fieldOptionId);
1405
- if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
1406
- (_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
1407
- }
1408
1407
  }
1409
1408
  }
1410
1409
  setValue(newValue, widgetUpdate = true) {
1411
- var _a;
1412
1410
  if (typeof newValue === UNDEFINED || newValue === null) {
1413
1411
  return true;
1414
1412
  }
1415
1413
  let newFinalValue;
1416
- switch (this.fieldType) {
1417
- case 'BOOLEAN':
1418
- newFinalValue = !!newValue;
1419
- break;
1420
- case this._formConfig.fieldTypes.boolean:
1421
- newFinalValue = !!newValue;
1422
- break;
1423
- case this._formConfig.fieldTypes.check:
1424
- newFinalValue = !!newValue;
1425
- break;
1426
- case this._formConfig.fieldTypes.array:
1427
- if (newValue === null || newValue === '') {
1428
- newFinalValue = [];
1429
- }
1430
- else if (!Array.isArray(newValue)) {
1431
- if (typeof (newValue) !== 'string') {
1432
- newValue = newValue.toString();
1433
- }
1434
- newFinalValue = newValue.split(',');
1435
- }
1436
- else {
1437
- newFinalValue = newValue;
1438
- }
1439
- break;
1440
- case this._formConfig.fieldTypes.map:
1441
- newFinalValue = newValue;
1442
- if (newFinalValue && this.widget && widgetUpdate) {
1443
- const latitude = parseFloat(newFinalValue[0]);
1444
- const longitude = parseFloat(newFinalValue[1]);
1445
- (_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
1446
- }
1447
- break;
1448
- default:
1414
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
1415
+ || this.fieldType === this._formConfig.fieldTypes.check) {
1416
+ newFinalValue = yn(newValue);
1417
+ }
1418
+ else if (this.fieldType === this._formConfig.fieldTypes.array
1419
+ || this.fieldType === this._formConfig.fieldTypes.map) {
1420
+ if (newValue === null || newValue === '') {
1421
+ newFinalValue = [];
1422
+ }
1423
+ else if (Array.isArray(newValue)) {
1449
1424
  newFinalValue = newValue;
1450
- break;
1425
+ }
1426
+ else {
1427
+ newFinalValue = newValue.toString().split(',');
1428
+ }
1429
+ }
1430
+ else {
1431
+ newFinalValue = newValue;
1451
1432
  }
1452
1433
  if (this._value !== newFinalValue) {
1453
1434
  this.setChanged(true);
1454
- this.setAttr(fldAttr.value, newFinalValue);
1435
+ if (widgetUpdate) {
1436
+ this.setAttr(fldAttr.value, newFinalValue);
1437
+ }
1438
+ else {
1439
+ this._value = newFinalValue;
1440
+ }
1455
1441
  }
1456
1442
  return true;
1457
1443
  }
@@ -1807,6 +1793,7 @@ class FormStructureAndData {
1807
1793
  enableField(code) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.enable(); }
1808
1794
  disableField(code) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.disable(); }
1809
1795
  getFieldValue(code) { var _a; return (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.getValue(); }
1796
+ getFieldOptionText(code) { var _a; return (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.getOptionText(); }
1810
1797
  getFieldOptions(code) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.getFieldOptions(); }
1811
1798
  setFieldValue(code, value) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setValue(value); }
1812
1799
  setFieldError(code, message, type = 'error') { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setError(code, message, type); }
@@ -2188,90 +2175,28 @@ class BasicFormComponent {
2188
2175
  this.cleanStart();
2189
2176
  this.customPreProcessing();
2190
2177
  }
2191
- getTitle() {
2192
- var _a;
2193
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTitle();
2194
- }
2195
- setTitle(title) {
2196
- var _a;
2197
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setTitle(title);
2198
- }
2199
- cleanData() {
2200
- var _a;
2201
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanData();
2202
- }
2203
- getCurrentState() {
2204
- var _a;
2205
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getCurrentState();
2206
- }
2207
- supportState(state) {
2208
- var _a;
2209
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.supportState(state);
2210
- }
2211
- changeState(state) {
2212
- var _a;
2213
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.changeState(state);
2214
- }
2215
- getStates() {
2216
- var _a;
2217
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.states;
2218
- }
2219
- getImmutableElement(name) {
2220
- var _a;
2221
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getImmutableElement(name);
2222
- }
2223
- getExtraInfo(name) {
2224
- var _a;
2225
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getExtraInfo(name);
2226
- }
2227
- getFields() {
2228
- var _a;
2229
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFields();
2230
- }
2231
- getFieldNames() {
2232
- var _a;
2233
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldNames();
2234
- }
2235
- getField(code) {
2236
- var _a;
2237
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getField(code);
2238
- }
2239
- enableField(code) {
2240
- var _a;
2241
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableField(code);
2242
- }
2243
- disableField(code) {
2244
- var _a;
2245
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableField(code);
2246
- }
2247
- getFieldValue(code) {
2248
- var _a;
2249
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldValue(code);
2250
- }
2251
- getFieldsValues(codes) {
2252
- var _a;
2253
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldsValues(codes);
2254
- }
2255
- getFieldOptions(code) {
2256
- var _a;
2257
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldOptions(code);
2258
- }
2259
- setFieldValue(code, value) {
2260
- var _a;
2261
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldValue(code, value);
2262
- }
2263
- setFieldRequired(code, required) {
2264
- var _a;
2265
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldRequired(code, required);
2266
- }
2267
- setFieldErrorMessage(code, errorMessage) {
2268
- var _a;
2269
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldErrorMessage(code, errorMessage);
2270
- }
2271
- setFieldError(code, message, type) {
2272
- var _a;
2273
- return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldError(code, message, type);
2274
- }
2178
+ getTitle() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTitle(); }
2179
+ setTitle(title) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setTitle(title); }
2180
+ cleanData() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanData(); }
2181
+ getCurrentState() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getCurrentState(); }
2182
+ supportState(state) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.supportState(state); }
2183
+ changeState(state) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.changeState(state); }
2184
+ getStates() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.states; }
2185
+ getImmutableElement(name) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getImmutableElement(name); }
2186
+ getExtraInfo(name) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getExtraInfo(name); }
2187
+ getFields() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFields(); }
2188
+ getFieldNames() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldNames(); }
2189
+ getField(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getField(code); }
2190
+ enableField(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableField(code); }
2191
+ disableField(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableField(code); }
2192
+ getFieldValue(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldValue(code); }
2193
+ getFieldOptionText(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldOptionText(code); }
2194
+ getFieldsValues(codes) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldsValues(codes); }
2195
+ getFieldOptions(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldOptions(code); }
2196
+ setFieldValue(code, value) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldValue(code, value); }
2197
+ setFieldRequired(code, required) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldRequired(code, required); }
2198
+ setFieldErrorMessage(code, errorMessage) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldErrorMessage(code, errorMessage); }
2199
+ setFieldError(code, message, type) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldError(code, message, type); }
2275
2200
  setFieldIntrinsicErrorMessage(code, message) {
2276
2201
  var _a;
2277
2202
  return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldIntrinsicErrorMessage(code, message);
@@ -3538,11 +3463,8 @@ class BasicFormComponent {
3538
3463
  this.tagFieldsWithError(requiredEmptyFields, null, this.formConfig.formStandardErrors.requiredField);
3539
3464
  for (const fieldCode of requiredEmptyFields) {
3540
3465
  const requiredEmptyField = this.getField(fieldCode);
3541
- if (requiredEmptyField && requiredEmptyField.widget
3542
- && requiredEmptyField.widget.focus) {
3543
- requiredEmptyField.widget.focus();
3544
- break;
3545
- }
3466
+ requiredEmptyField === null || requiredEmptyField === void 0 ? void 0 : requiredEmptyField.focus();
3467
+ break;
3546
3468
  }
3547
3469
  }
3548
3470
  const validationIssueFields = this.getFieldsWithValidationIssues(null, sectionCode);
@@ -3551,11 +3473,8 @@ class BasicFormComponent {
3551
3473
  this.setError(this.formConfig.formStandardErrors.typeWarning, this.formConfig.formStandardErrors.validationTitle, this.formConfig.formStandardErrors.validationFields);
3552
3474
  for (const fieldCode of validationIssueFields) {
3553
3475
  const validationIssueField = this.getField(fieldCode);
3554
- if (validationIssueField && validationIssueField.widget
3555
- && validationIssueField.widget.focus) {
3556
- validationIssueField.widget.focus();
3557
- break;
3558
- }
3476
+ validationIssueField.focus();
3477
+ break;
3559
3478
  }
3560
3479
  }
3561
3480
  return validationError;