tuain-ng-forms-lib 0.12.17 → 0.12.21

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 CHANGED
@@ -306,6 +306,7 @@ This set of methods allow subclass to access and modify fields in the form.
306
306
  | `setFieldValue` | Change the current value of a field |
307
307
  | `setFieldErrorMessage` | Defines an error message for a field |
308
308
  | `setFieldOptions` | Define the posible values of the field with an array of values and description text |
309
+ | `setFieldRequired` | Change an status attribute of the field to determine if it is required |
309
310
  | `applyProcessToFieldSet` | Execute a process on all the fields specified in an array, section or sub-section. If the fields are not specified, the execition will be over the whole set of fields in the form `(processFunc, fieldArray?, sectionCode?, subSectionCode?)`|
310
311
  | `cleanFields` | Clean all the fields specified in an array, section or sub-section using their default value. If the fields are not specified, the execition will be over the whole set of fields in the form `(fieldArray?, sectionCode?, subSectionCode?)`|
311
312
  | `getRequiredFields` | Obtain all the required fields specified in an array, section or sub-section using their default value. If the fields are not specified, the execition will be over the whole set of fields in the form `(fieldArray?, sectionCode?, subSectionCode?)`|
@@ -408,4 +409,4 @@ but common operations in the forms.
408
409
 
409
410
  ## License
410
411
 
411
- [MIT](https://choosealicense.com/licenses/mit/)
412
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -1365,17 +1365,17 @@
1365
1365
  if (!this.sorting.columnName || !this.sorting.direction) {
1366
1366
  return;
1367
1367
  }
1368
- this.tableRecords = this.tableRecords
1369
- .sort(function (a, b) { return _this.recordCompare(a, b, _this.sorting.columnName, _this.sorting.direction); });
1368
+ this.tableRecords.sort(function (a, b) { return _this.recordCompare(a, b, _this.sorting.columnName, _this.sorting.direction); });
1369
+ this.updateVisibleRecords();
1370
1370
  };
1371
1371
  RecordTable.prototype.recordCompare = function (recordA, recordB, columnCompare, direction) {
1372
1372
  var recordAColumn = recordA.getFieldValue(columnCompare);
1373
1373
  var recordBColumn = recordB.getFieldValue(columnCompare);
1374
1374
  var result = 0;
1375
- if (recordAColumn.fieldValue < recordBColumn.fieldValue) {
1375
+ if (recordAColumn < recordBColumn) {
1376
1376
  result = -1;
1377
1377
  }
1378
- else if (recordAColumn.fieldValue > recordBColumn.fieldValue) {
1378
+ else if (recordAColumn > recordBColumn) {
1379
1379
  result = 1;
1380
1380
  }
1381
1381
  return direction === componentConstants.TABLE_SORT_ASCENDING ? result : -result;
@@ -1937,13 +1937,40 @@
1937
1937
  var FIELD_TOOLTIP = 'tooltipText';
1938
1938
  var FIELD_INFO = 'info';
1939
1939
  var FIELD_EDITABLE = 'editable';
1940
+ var EMAIL_FORMAT = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$';
1941
+ // Norbey ".+@([\da-z\.-]+)\.([a-z\.]{2,6})"
1942
+ var FIELD_TYPES = {
1943
+ array: 'ARRAY',
1944
+ check: 'CHECK',
1945
+ date: 'DATE',
1946
+ daterange: 'DATERANGE',
1947
+ time: 'TIME',
1948
+ timerange: 'TIMERANGE',
1949
+ map: 'MAP',
1950
+ number: 'NUMBER',
1951
+ decimal: 'DECIMAL',
1952
+ currency: 'CURRENCY',
1953
+ select: 'SELECT',
1954
+ typeahead: 'TYPEAHEAD',
1955
+ text: 'TEXT',
1956
+ password: 'PASSWORD',
1957
+ label: 'LABEL',
1958
+ html: 'HTML',
1959
+ title: 'TITLE',
1960
+ message: 'MESSAGE',
1961
+ link: 'LINK',
1962
+ warning: 'WARNING',
1963
+ avatar: 'AVATAR',
1964
+ email: 'EMAIL',
1965
+ phone: 'PHONE',
1966
+ };
1940
1967
  var STD_MAX_LENGTH = 50;
1941
1968
  var BIG_MAX_LENGTH = 500;
1942
1969
  var FieldDescriptor = /** @class */ (function (_super) {
1943
1970
  __extends(FieldDescriptor, _super);
1944
1971
  function FieldDescriptor(inputFieldReceived) {
1945
1972
  var _this = this;
1946
- var _a, _b, _c, _d, _e, _f, _g;
1973
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1947
1974
  _this = _super.call(this, inputFieldReceived) || this;
1948
1975
  _this._editionFinish = new rxjs.Subject();
1949
1976
  _this._editionPartial = new rxjs.Subject();
@@ -1970,9 +1997,12 @@
1970
1997
  _this.defaultEditable = _this.enabled;
1971
1998
  _this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
1972
1999
  _this.errorMessage = fieldReceived.errorMessage || '';
1973
- _this.errorCode = fieldReceived.errorCode || '00';
1974
- _this.outputOnly = (_g = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _g !== void 0 ? _g : false;
2000
+ _this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
2001
+ _this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
1975
2002
  _this.setFieldOptions(fieldReceived.fieldOptions);
2003
+ _this._intrinsicErrorMessage = (_this.fieldType === FIELD_TYPES.email)
2004
+ ? "El valor de " + _this.fieldTitle + " no corresponde a un correo v\u00E1lido"
2005
+ : "El valor de " + _this.fieldTitle + " no se ajusta al formato establecido";
1976
2006
  return _this;
1977
2007
  }
1978
2008
  Object.defineProperty(FieldDescriptor.prototype, "name", {
@@ -1995,6 +2025,18 @@
1995
2025
  enumerable: false,
1996
2026
  configurable: true
1997
2027
  });
2028
+ Object.defineProperty(FieldDescriptor.prototype, "validating", {
2029
+ get: function () { return this._onValidation; },
2030
+ set: function (isValidating) { this._onValidation = isValidating; },
2031
+ enumerable: false,
2032
+ configurable: true
2033
+ });
2034
+ FieldDescriptor.prototype.setIntrinsicErrorMessage = function (message) { this._intrinsicErrorMessage = message; };
2035
+ Object.defineProperty(FieldDescriptor.prototype, "intrinsicErrorMessage", {
2036
+ set: function (message) { this.setIntrinsicErrorMessage(message); },
2037
+ enumerable: false,
2038
+ configurable: true
2039
+ });
1998
2040
  Object.defineProperty(FieldDescriptor.prototype, "fieldValue", {
1999
2041
  get: function () { return this.getValue(); },
2000
2042
  enumerable: false,
@@ -2025,9 +2067,29 @@
2025
2067
  enumerable: false,
2026
2068
  configurable: true
2027
2069
  });
2028
- FieldDescriptor.prototype.notifyEditionPartial = function () { this._editionPartial.next(this.fieldCode); };
2029
- FieldDescriptor.prototype.notifyEditionFinish = function () { this._editionFinish.next(this.fieldCode); };
2030
- FieldDescriptor.prototype.notifyEditionDetailRequest = function () { this._detailRequest.next(this.fieldCode); };
2070
+ FieldDescriptor.prototype.notifyEditionPartial = function () {
2071
+ var intrinsicValidation = true;
2072
+ this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
2073
+ };
2074
+ FieldDescriptor.prototype.notifyEditionFinish = function () {
2075
+ var intrinsicValidation = true;
2076
+ var fieldExpression = (this.fieldType === FIELD_TYPES.email) ? EMAIL_FORMAT : this.fieldFormat;
2077
+ var fieldFormat = new RegExp(fieldExpression);
2078
+ var fieldValue = this.getValue();
2079
+ if (fieldValue && fieldFormat) {
2080
+ intrinsicValidation = fieldFormat.test(fieldValue);
2081
+ if (!intrinsicValidation) {
2082
+ var message = (this.fieldType === FIELD_TYPES.email)
2083
+ ? "El valor de " + this.fieldTitle + " no corresponde a un correo v\u00E1lido"
2084
+ : "El valor de " + this.fieldTitle + " no se ajusta al formato establecido";
2085
+ this.setError('99', message);
2086
+ }
2087
+ }
2088
+ this._editionFinish.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
2089
+ };
2090
+ FieldDescriptor.prototype.notifyEditionDetailRequest = function () {
2091
+ this._detailRequest.next(this.fieldCode);
2092
+ };
2031
2093
  FieldDescriptor.prototype.showLabel = function () { this.visibleLabel = true; };
2032
2094
  FieldDescriptor.prototype.hideLabel = function () { this.visibleLabel = false; };
2033
2095
  FieldDescriptor.prototype.changed = function () { this.hasChanged = true; };
@@ -2044,11 +2106,35 @@
2044
2106
  if (editable === void 0) { editable = true; }
2045
2107
  (editable) ? this.enable() : this.disable();
2046
2108
  };
2047
- FieldDescriptor.prototype.isEmpty = function () { return this.getValue() === '' || this.getValue() === undefined || this.getValue() === null; };
2048
- FieldDescriptor.prototype.getErrorCode = function () { return this.errorCode; };
2049
- FieldDescriptor.prototype.setErrorCode = function (code) { this.errorCode = code; };
2050
- FieldDescriptor.prototype.getErrorMessage = function () { return this.errorMessage; };
2051
- FieldDescriptor.prototype.setErrorMessage = function (msg) { this.errorMessage = msg; };
2109
+ FieldDescriptor.prototype.setError = function (code, message, type) {
2110
+ if (type === void 0) { type = 'error'; }
2111
+ this.errorType = (code === '00') ? '' : type;
2112
+ this.errorCode = code;
2113
+ this.errorMessage = message;
2114
+ };
2115
+ FieldDescriptor.prototype.getError = function () { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; };
2116
+ Object.defineProperty(FieldDescriptor.prototype, "error", {
2117
+ get: function () { return this.getError(); },
2118
+ set: function (errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); },
2119
+ enumerable: false,
2120
+ configurable: true
2121
+ });
2122
+ FieldDescriptor.prototype.getErrorCode = function () { return this.getError().code; };
2123
+ FieldDescriptor.prototype.setErrorCode = function (code) { this.setError(code, this.errorMessage); };
2124
+ FieldDescriptor.prototype.getErrorMessage = function () { return this.getError().message; };
2125
+ FieldDescriptor.prototype.setErrorMessage = function (msg) { this.setError(this.errorCode, msg); };
2126
+ FieldDescriptor.prototype.isEmpty = function () {
2127
+ var fieldCurrentValue = this.getValue();
2128
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
2129
+ return true;
2130
+ }
2131
+ if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
2132
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
2133
+ return true;
2134
+ }
2135
+ ;
2136
+ return fieldCurrentValue === '';
2137
+ };
2052
2138
  FieldDescriptor.prototype.getValue = function () {
2053
2139
  var _a;
2054
2140
  switch (this.fieldType) {
@@ -2721,6 +2807,19 @@
2721
2807
  var fieldObject = this.getFieldObject(fieldCode);
2722
2808
  return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
2723
2809
  };
2810
+ FormStructureAndData.prototype.setFieldError = function (code, message, type) {
2811
+ if (type === void 0) { type = 'error'; }
2812
+ var fieldObject = this.getFieldObject(code);
2813
+ return (fieldObject) ? fieldObject.setError(code, message, type) : null;
2814
+ };
2815
+ FormStructureAndData.prototype.setFieldIntrinsicErrorMessage = function (code, message) {
2816
+ var fieldObject = this.getFieldObject(code);
2817
+ return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
2818
+ };
2819
+ FormStructureAndData.prototype.setFieldRequired = function (fieldCode, required) {
2820
+ var fieldObject = this.getFieldObject(fieldCode);
2821
+ return (fieldObject) ? fieldObject.required = required : null;
2822
+ };
2724
2823
  FormStructureAndData.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) {
2725
2824
  var fieldObject = this.getFieldObject(fieldCode);
2726
2825
  return (fieldObject) ? fieldObject.setErrorMessage(errorMessage) : null;
@@ -3217,7 +3316,13 @@
3217
3316
  BasicFormComponent.prototype.getFieldsValues = function (fieldCodesArray) { return this.formStructure.getFieldsValues(fieldCodesArray); };
3218
3317
  BasicFormComponent.prototype.getFieldOptions = function (fieldCode) { return this.formStructure.getFieldOptions(fieldCode); };
3219
3318
  BasicFormComponent.prototype.setFieldValue = function (fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); };
3319
+ BasicFormComponent.prototype.setFieldRequired = function (fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); };
3220
3320
  BasicFormComponent.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); };
3321
+ BasicFormComponent.prototype.setFieldError = function (code, message, type) {
3322
+ if (type === void 0) { type = 'error'; }
3323
+ return this.formStructure.setFieldError(code, message, type);
3324
+ };
3325
+ BasicFormComponent.prototype.setFieldIntrinsicErrorMessage = function (code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); };
3221
3326
  BasicFormComponent.prototype.setFieldOptions = function (fieldCode, optionsArray, idAttribute, nameAttribute) {
3222
3327
  return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
3223
3328
  };
@@ -3436,8 +3541,14 @@
3436
3541
  var formFields = this.formStructure.getFields();
3437
3542
  if (Array.isArray(formFields)) {
3438
3543
  formFields.forEach(function (field) {
3439
- field.editionFinish.subscribe(function (code) { return _this.startFieldValidation(code); });
3440
- field.editionPartial.subscribe(function (code) { return _this.startFieldInputValidation(code); });
3544
+ field.editionFinish.subscribe(function (event) {
3545
+ var code = event.code, intrinsicValidation = event.intrinsicValidation;
3546
+ _this.startFieldValidation(code, intrinsicValidation);
3547
+ });
3548
+ field.editionPartial.subscribe(function (event) {
3549
+ var code = event.code, intrinsicValidation = event.intrinsicValidation;
3550
+ _this.startFieldInputValidation(code, intrinsicValidation);
3551
+ });
3441
3552
  field.detailRequest.subscribe(function (code) { return _this.showFieldInfo(code); });
3442
3553
  });
3443
3554
  }
@@ -3465,8 +3576,9 @@
3465
3576
  }
3466
3577
  };
3467
3578
  BasicFormComponent.prototype.formInit = function (params) {
3579
+ var _a;
3468
3580
  return __awaiter(this, void 0, void 0, function () {
3469
- var initialState, formDefinition, _g, _h, inputFieldData, fieldCode, fieldValue, recordResponse;
3581
+ var initialState, formDefinition, _g, _h, inputFieldData, fieldCode, fieldValue, fieldCodes, index, fieldCode, fieldValue, recordResponse;
3470
3582
  var e_2, _j;
3471
3583
  return __generator(this, function (_k) {
3472
3584
  switch (_k.label) {
@@ -3492,21 +3604,31 @@
3492
3604
  initialState = this.formStructure.defaultState;
3493
3605
  }
3494
3606
  this.formStructure.changeState(initialState || this.formStructure.defaultState);
3495
- try {
3496
- for (_g = __values(this.inputDataFields), _h = _g.next(); !_h.done; _h = _g.next()) {
3497
- inputFieldData = _h.value;
3498
- fieldCode = inputFieldData.fieldCode, fieldValue = inputFieldData.fieldValue;
3499
- if (fieldCode) {
3500
- this.setFieldValue(inputFieldData.fieldCode, fieldValue);
3607
+ if (Array.isArray(this.inputDataFields)) {
3608
+ try {
3609
+ for (_g = __values(this.inputDataFields), _h = _g.next(); !_h.done; _h = _g.next()) {
3610
+ inputFieldData = _h.value;
3611
+ fieldCode = inputFieldData.fieldCode, fieldValue = inputFieldData.fieldValue;
3612
+ if (fieldCode) {
3613
+ this.setFieldValue(fieldCode, fieldValue);
3614
+ }
3501
3615
  }
3502
3616
  }
3617
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3618
+ finally {
3619
+ try {
3620
+ if (_h && !_h.done && (_j = _g.return)) _j.call(_g);
3621
+ }
3622
+ finally { if (e_2) throw e_2.error; }
3623
+ }
3503
3624
  }
3504
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3505
- finally {
3506
- try {
3507
- if (_h && !_h.done && (_j = _g.return)) _j.call(_g);
3625
+ else {
3626
+ fieldCodes = Object.keys((_a = this.inputDataFields) !== null && _a !== void 0 ? _a : {});
3627
+ for (index = 0; index < fieldCodes.length; index++) {
3628
+ fieldCode = fieldCodes[index];
3629
+ fieldValue = this.inputDataFields[fieldCode];
3630
+ this.setFieldValue(fieldCode, fieldValue);
3508
3631
  }
3509
- finally { if (e_2) throw e_2.error; }
3510
3632
  }
3511
3633
  return [4 /*yield*/, this.requestFormAction(componentConstants.FORMACTION_GETDATA)];
3512
3634
  case 4:
@@ -3893,7 +4015,8 @@
3893
4015
  _this.fieldValidationsFinish[fieldCode].push(callbackMethod);
3894
4016
  });
3895
4017
  };
3896
- BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode) {
4018
+ BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode, intrinsicValidation) {
4019
+ if (intrinsicValidation === void 0) { intrinsicValidation = true; }
3897
4020
  return __awaiter(this, void 0, void 0, function () {
3898
4021
  var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_1, validationCallbacks_1_1, validationMethod, continueValidationPromise;
3899
4022
  var e_10, _g;
@@ -3932,7 +4055,8 @@
3932
4055
  });
3933
4056
  });
3934
4057
  };
3935
- BasicFormComponent.prototype.startFieldValidation = function (fieldCode) {
4058
+ BasicFormComponent.prototype.startFieldValidation = function (fieldCode, intrinsicValidation) {
4059
+ if (intrinsicValidation === void 0) { intrinsicValidation = true; }
3936
4060
  return __awaiter(this, void 0, void 0, function () {
3937
4061
  var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_2, validationCallbacks_2_1, validationMethod, clientValidationPromise, clientValidationResults, continueValidation;
3938
4062
  var e_11, _g;
@@ -3940,7 +4064,7 @@
3940
4064
  switch (_h.label) {
3941
4065
  case 0:
3942
4066
  fieldToValidate = this.getField(fieldCode);
3943
- if (!fieldToValidate) {
4067
+ if (!fieldToValidate || !intrinsicValidation) {
3944
4068
  return [2 /*return*/];
3945
4069
  }
3946
4070
  fieldToValidate.setErrorMessage('');
@@ -3988,6 +4112,7 @@
3988
4112
  finish = true;
3989
4113
  validationResult = null;
3990
4114
  if (!fieldObj.backend) return [3 /*break*/, 2];
4115
+ fieldObj.validating = true;
3991
4116
  return [4 /*yield*/, this
3992
4117
  .requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode)];
3993
4118
  case 1:
@@ -4005,7 +4130,9 @@
4005
4130
  fieldObj.setErrorMessage(this.errorMessage);
4006
4131
  this.displayValidationServerError();
4007
4132
  _g.label = 5;
4008
- case 5: return [2 /*return*/];
4133
+ case 5:
4134
+ fieldObj.validating = false;
4135
+ return [2 /*return*/];
4009
4136
  }
4010
4137
  });
4011
4138
  });