tuain-ng-forms-lib 12.0.2 → 12.0.3

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.
@@ -51,50 +51,22 @@ ActionComponent.propDecorators = {
51
51
  showLabel: [{ type: Input }]
52
52
  };
53
53
 
54
- const MONITORED_ATTRIBUTES = {
55
- _maxLength: 'maxLength',
56
- _onValidation: 'onValidation',
57
- _fieldValue: 'value',
58
- captureType: 'captureType',
59
- fieldTitle: 'title',
60
- fieldType: 'type',
61
- errorMessage: 'errorMessage',
62
- errorType: 'errorType',
63
- errorCode: 'errorCode',
64
- visibleLabel: 'visibleLabel',
65
- fieldRequired: 'required',
66
- fieldOptions: 'options',
67
- };
68
54
  class FieldComponent {
69
55
  ngOnInit() {
70
- var _a;
56
+ var _a, _b;
71
57
  if (this.fieldObject) {
72
58
  this.formConfig = (_a = this.fieldObject) === null || _a === void 0 ? void 0 : _a._formConfig;
73
- // Atributos estáticos
74
- this.code = this.fieldObject.fieldCode;
75
- this.fieldInfo = this.fieldObject.fieldInfo;
76
- this.fieldAlignment = this.fieldObject.fieldAlignment;
77
- this.tooltipText = this.fieldObject.tooltipText;
78
- // Cargue inicial
79
- this.maxLength = this.fieldObject._maxLength;
80
- this.onValidation = this.fieldObject._onValidation;
81
- this.value = this.fieldObject._fieldValue;
82
- this.captureType = this.fieldObject.captureType;
83
- this.title = this.fieldObject.fieldTitle;
84
- this.type = this.fieldObject.fieldType;
85
- this.errorMessage = this.fieldObject.errorMessage;
86
- this.errorType = this.fieldObject.errorType;
87
- this.errorCode = this.fieldObject.errorCode;
88
- this.visibleLabel = this.fieldObject.visibleLabel;
89
- this.required = this.fieldObject.fieldRequired;
90
- this.options = this.fieldObject.fieldOptions;
91
- this.fieldObject.widget = this;
92
- // Atributos dinámicos
59
+ // Inicialización
60
+ const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
61
+ for (let index = 0; index < mapping.length; index++) {
62
+ const [fieldAttr, compAttr] = mapping[index];
63
+ this[compAttr.toString()] = (_b = this.fieldObject) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
64
+ }
65
+ // Subscripción a cambios en atributos
93
66
  this.fieldObject.attributeChange.subscribe(event => {
94
- const { name, value } = event;
95
- if (this[MONITORED_ATTRIBUTES[name]]) {
96
- this[MONITORED_ATTRIBUTES[name]] = value;
97
- }
67
+ const { name: fieldAttr, value } = event;
68
+ const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
69
+ this.hasOwnProperty(compAttr) && (this[compAttr] = value);
98
70
  });
99
71
  }
100
72
  this.start();
@@ -245,6 +217,8 @@ class Filter {
245
217
  }
246
218
  }
247
219
 
220
+ const NO_ERROR = '00';
221
+ const HEADER$1 = 'HEADER';
248
222
  const elementTypes = {
249
223
  action: 'ACTION',
250
224
  field: 'FIELD',
@@ -1276,7 +1250,7 @@ class RecordFormSection {
1276
1250
  supportMode(state) { return this.viewOnState(state); }
1277
1251
  }
1278
1252
 
1279
- const HEADER$1 = 'HEADER';
1253
+ const HEADER = 'HEADER';
1280
1254
  class FormAction extends FormElement {
1281
1255
  constructor(actionDefinition, formConfig) {
1282
1256
  var _a, _b;
@@ -1287,7 +1261,7 @@ class FormAction extends FormElement {
1287
1261
  this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
1288
1262
  this.actionName = actionDefinition.actionTitle;
1289
1263
  this.iconName = actionDefinition.iconName || this.actionCode;
1290
- this.location = actionDefinition.position || HEADER$1;
1264
+ this.location = actionDefinition.position || HEADER;
1291
1265
  this.backend = (_a = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.serverAction) !== null && _a !== void 0 ? _a : false;
1292
1266
  this.newState = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.newState;
1293
1267
  this.customAttributes = (_b = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.customAttributes) !== null && _b !== void 0 ? _b : null;
@@ -1450,10 +1424,11 @@ class FieldDescriptor extends FormElement {
1450
1424
  clean() { this.setValue(this.defaultValue || ''); }
1451
1425
  get backend() { return this.validateOnServer; }
1452
1426
  setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
1453
- hasError() { return this.errorCode !== '00'; }
1427
+ hasError() { return this.errorCode !== NO_ERROR; }
1428
+ resetError() { (this.errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
1454
1429
  setError(code, message, type = DEFAULT_ERROR_TYPE) {
1455
- this.setAttr(fldAttr.errorCode, code !== null && code !== void 0 ? code : '00');
1456
- this.setAttr(fldAttr.errorType, (this.errorCode === '00') ? '' : type);
1430
+ this.setAttr(fldAttr.errorCode, code !== null && code !== void 0 ? code : NO_ERROR);
1431
+ this.setAttr(fldAttr.errorType, (this.errorCode === NO_ERROR) ? '' : type);
1457
1432
  this.setAttr(fldAttr.errorMessage, message !== null && message !== void 0 ? message : '');
1458
1433
  }
1459
1434
  getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
@@ -1646,8 +1621,6 @@ class FieldDescriptor extends FormElement {
1646
1621
  }
1647
1622
  }
1648
1623
 
1649
- const HEADER = 'HEADER';
1650
- const NO_ERROR = '00';
1651
1624
  class FormStructureAndData {
1652
1625
  constructor(definitionReceived, formConfig) {
1653
1626
  this._fieldsObj = {};
@@ -1832,7 +1805,7 @@ class FormStructureAndData {
1832
1805
  return this._actions;
1833
1806
  }
1834
1807
  getHeaderActions() {
1835
- return this._actions.filter(actionItem => actionItem.location === HEADER);
1808
+ return this._actions.filter(actionItem => actionItem.location === HEADER$1);
1836
1809
  }
1837
1810
  getFieldObject(elementId) {
1838
1811
  return (this._fieldsObj && elementId && this._fieldsObj[elementId])
@@ -2694,7 +2667,7 @@ class BasicFormComponent {
2694
2667
  this.errorDetail = recordResponse.errorDetail;
2695
2668
  }
2696
2669
  errorOccured() {
2697
- return (this.errorCode !== '00');
2670
+ return (this.errorCode !== NO_ERROR);
2698
2671
  }
2699
2672
  changeState(state) { return this.formStructure.changeState(state); }
2700
2673
  changeFormMode(state) { return this.changeState(state); }
@@ -2710,7 +2683,7 @@ class BasicFormComponent {
2710
2683
  formData: this.formStructure.getPayload(),
2711
2684
  immutableData: this.formStructure.immutableData,
2712
2685
  };
2713
- this.errorCode = '00';
2686
+ this.errorCode = NO_ERROR;
2714
2687
  this.errorMessage = '';
2715
2688
  this.errorDetail = '';
2716
2689
  this.inServerProcess = true;
@@ -2929,8 +2902,7 @@ class BasicFormComponent {
2929
2902
  if (!fieldToValidate) {
2930
2903
  return false;
2931
2904
  }
2932
- fieldToValidate.setErrorMessage('');
2933
- fieldToValidate.setErrorCode('00');
2905
+ fieldToValidate.resetError();
2934
2906
  const validationCallbacks = this.fieldInputValidation[fieldCode];
2935
2907
  if (validationCallbacks) {
2936
2908
  const clientValidationPromises = [];
@@ -2948,8 +2920,7 @@ class BasicFormComponent {
2948
2920
  if (!fieldToValidate || !intrinsicValidation) {
2949
2921
  return;
2950
2922
  }
2951
- fieldToValidate.setErrorMessage('');
2952
- fieldToValidate.setErrorCode('00');
2923
+ fieldToValidate.resetError();
2953
2924
  const validationCallbacks = this.fieldValidationsStart[fieldCode];
2954
2925
  if (validationCallbacks) {
2955
2926
  const clientValidationPromises = [];