tuain-ng-forms-lib 0.12.18 → 0.12.22

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,41 @@
1937
1937
  var FIELD_TOOLTIP = 'tooltipText';
1938
1938
  var FIELD_INFO = 'info';
1939
1939
  var FIELD_EDITABLE = 'editable';
1940
+ var FIELD_TYPES = {
1941
+ array: 'ARRAY',
1942
+ check: 'CHECK',
1943
+ date: 'DATE',
1944
+ daterange: 'DATERANGE',
1945
+ time: 'TIME',
1946
+ timerange: 'TIMERANGE',
1947
+ map: 'MAP',
1948
+ number: 'NUMBER',
1949
+ decimal: 'DECIMAL',
1950
+ currency: 'CURRENCY',
1951
+ select: 'SELECT',
1952
+ typeahead: 'TYPEAHEAD',
1953
+ text: 'TEXT',
1954
+ password: 'PASSWORD',
1955
+ label: 'LABEL',
1956
+ html: 'HTML',
1957
+ title: 'TITLE',
1958
+ message: 'MESSAGE',
1959
+ link: 'LINK',
1960
+ warning: 'WARNING',
1961
+ avatar: 'AVATAR',
1962
+ email: 'EMAIL',
1963
+ phone: 'PHONE',
1964
+ };
1965
+ var FIELD_TYPES_FORMATS = {
1966
+ EMAIL: '^\\w+([\\.-]?\\w+)@\\w+([\\.-]?\\w+)(\\.\\w{2,3})+$',
1967
+ };
1940
1968
  var STD_MAX_LENGTH = 50;
1941
1969
  var BIG_MAX_LENGTH = 500;
1942
1970
  var FieldDescriptor = /** @class */ (function (_super) {
1943
1971
  __extends(FieldDescriptor, _super);
1944
1972
  function FieldDescriptor(inputFieldReceived) {
1945
1973
  var _this = this;
1946
- var _a, _b, _c, _d, _e, _f, _g;
1974
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1947
1975
  _this = _super.call(this, inputFieldReceived) || this;
1948
1976
  _this._editionFinish = new rxjs.Subject();
1949
1977
  _this._editionPartial = new rxjs.Subject();
@@ -1961,7 +1989,7 @@
1961
1989
  var defaultTypeAlignment = (tableFieldStyles[_this.fieldType] != null) ? tableFieldStyles[_this.fieldType]['text-align'] : 'left';
1962
1990
  _this.fieldAlignment = (fieldReceived.alignment != null) ? fieldReceived.alignment.toLowerCase() : defaultTypeAlignment;
1963
1991
  _this.fieldInfo = fieldReceived.info || '';
1964
- _this.fieldFormat = fieldReceived.format || '';
1992
+ _this.fieldFormat = fieldReceived.format || null;
1965
1993
  _this.validateOnServer = (_c = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.serverAction) !== null && _c !== void 0 ? _c : false;
1966
1994
  _this.customAttributes = (_d = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.customAttributes) !== null && _d !== void 0 ? _d : null;
1967
1995
  _this.setVisibility(fieldReceived.visible);
@@ -1970,9 +1998,12 @@
1970
1998
  _this.defaultEditable = _this.enabled;
1971
1999
  _this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
1972
2000
  _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;
2001
+ _this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
2002
+ _this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
1975
2003
  _this.setFieldOptions(fieldReceived.fieldOptions);
2004
+ _this._intrinsicErrorMessage = (_this.fieldType === FIELD_TYPES.email)
2005
+ ? "El valor de " + _this.fieldTitle + " no corresponde a un correo v\u00E1lido"
2006
+ : "El valor de " + _this.fieldTitle + " no se ajusta al formato establecido";
1976
2007
  return _this;
1977
2008
  }
1978
2009
  Object.defineProperty(FieldDescriptor.prototype, "name", {
@@ -1995,6 +2026,18 @@
1995
2026
  enumerable: false,
1996
2027
  configurable: true
1997
2028
  });
2029
+ Object.defineProperty(FieldDescriptor.prototype, "validating", {
2030
+ get: function () { return this._onValidation; },
2031
+ set: function (isValidating) { this._onValidation = isValidating; },
2032
+ enumerable: false,
2033
+ configurable: true
2034
+ });
2035
+ FieldDescriptor.prototype.setIntrinsicErrorMessage = function (message) { this._intrinsicErrorMessage = message; };
2036
+ Object.defineProperty(FieldDescriptor.prototype, "intrinsicErrorMessage", {
2037
+ set: function (message) { this.setIntrinsicErrorMessage(message); },
2038
+ enumerable: false,
2039
+ configurable: true
2040
+ });
1998
2041
  Object.defineProperty(FieldDescriptor.prototype, "fieldValue", {
1999
2042
  get: function () { return this.getValue(); },
2000
2043
  enumerable: false,
@@ -2025,9 +2068,29 @@
2025
2068
  enumerable: false,
2026
2069
  configurable: true
2027
2070
  });
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); };
2071
+ FieldDescriptor.prototype.notifyEditionPartial = function () {
2072
+ var intrinsicValidation = true;
2073
+ this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
2074
+ };
2075
+ FieldDescriptor.prototype.notifyEditionFinish = function () {
2076
+ var _a, _b;
2077
+ var intrinsicValidation = true;
2078
+ var fieldDefaultFormat = (FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType])
2079
+ ? new RegExp(FIELD_TYPES_FORMATS === null || FIELD_TYPES_FORMATS === void 0 ? void 0 : FIELD_TYPES_FORMATS[this.fieldType]) : null;
2080
+ var fieldFormat = (this.fieldFormat) ? new RegExp(this.fieldFormat) : null;
2081
+ var fieldValue = this.getValue();
2082
+ if (fieldValue && (fieldDefaultFormat || fieldFormat)) {
2083
+ intrinsicValidation = ((_a = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _a !== void 0 ? _a : true)
2084
+ && ((_b = fieldFormat === null || fieldFormat === void 0 ? void 0 : fieldFormat.test(fieldValue)) !== null && _b !== void 0 ? _b : true);
2085
+ if (!intrinsicValidation) {
2086
+ this.setError('99', this._intrinsicErrorMessage);
2087
+ }
2088
+ }
2089
+ this._editionFinish.next({ code: this.fieldCode, intrinsicValidation: intrinsicValidation });
2090
+ };
2091
+ FieldDescriptor.prototype.notifyEditionDetailRequest = function () {
2092
+ this._detailRequest.next(this.fieldCode);
2093
+ };
2031
2094
  FieldDescriptor.prototype.showLabel = function () { this.visibleLabel = true; };
2032
2095
  FieldDescriptor.prototype.hideLabel = function () { this.visibleLabel = false; };
2033
2096
  FieldDescriptor.prototype.changed = function () { this.hasChanged = true; };
@@ -2044,11 +2107,35 @@
2044
2107
  if (editable === void 0) { editable = true; }
2045
2108
  (editable) ? this.enable() : this.disable();
2046
2109
  };
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; };
2110
+ FieldDescriptor.prototype.setError = function (code, message, type) {
2111
+ if (type === void 0) { type = 'error'; }
2112
+ this.errorType = (code === '00') ? '' : type;
2113
+ this.errorCode = code;
2114
+ this.errorMessage = message;
2115
+ };
2116
+ FieldDescriptor.prototype.getError = function () { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; };
2117
+ Object.defineProperty(FieldDescriptor.prototype, "error", {
2118
+ get: function () { return this.getError(); },
2119
+ set: function (errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); },
2120
+ enumerable: false,
2121
+ configurable: true
2122
+ });
2123
+ FieldDescriptor.prototype.getErrorCode = function () { return this.getError().code; };
2124
+ FieldDescriptor.prototype.setErrorCode = function (code) { this.setError(code, this.errorMessage); };
2125
+ FieldDescriptor.prototype.getErrorMessage = function () { return this.getError().message; };
2126
+ FieldDescriptor.prototype.setErrorMessage = function (msg) { this.setError(this.errorCode, msg); };
2127
+ FieldDescriptor.prototype.isEmpty = function () {
2128
+ var fieldCurrentValue = this.getValue();
2129
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
2130
+ return true;
2131
+ }
2132
+ if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
2133
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
2134
+ return true;
2135
+ }
2136
+ ;
2137
+ return fieldCurrentValue === '';
2138
+ };
2052
2139
  FieldDescriptor.prototype.getValue = function () {
2053
2140
  var _a;
2054
2141
  switch (this.fieldType) {
@@ -2721,6 +2808,19 @@
2721
2808
  var fieldObject = this.getFieldObject(fieldCode);
2722
2809
  return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
2723
2810
  };
2811
+ FormStructureAndData.prototype.setFieldError = function (code, message, type) {
2812
+ if (type === void 0) { type = 'error'; }
2813
+ var fieldObject = this.getFieldObject(code);
2814
+ return (fieldObject) ? fieldObject.setError(code, message, type) : null;
2815
+ };
2816
+ FormStructureAndData.prototype.setFieldIntrinsicErrorMessage = function (code, message) {
2817
+ var fieldObject = this.getFieldObject(code);
2818
+ return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
2819
+ };
2820
+ FormStructureAndData.prototype.setFieldRequired = function (fieldCode, required) {
2821
+ var fieldObject = this.getFieldObject(fieldCode);
2822
+ return (fieldObject) ? fieldObject.required = required : null;
2823
+ };
2724
2824
  FormStructureAndData.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) {
2725
2825
  var fieldObject = this.getFieldObject(fieldCode);
2726
2826
  return (fieldObject) ? fieldObject.setErrorMessage(errorMessage) : null;
@@ -3217,7 +3317,13 @@
3217
3317
  BasicFormComponent.prototype.getFieldsValues = function (fieldCodesArray) { return this.formStructure.getFieldsValues(fieldCodesArray); };
3218
3318
  BasicFormComponent.prototype.getFieldOptions = function (fieldCode) { return this.formStructure.getFieldOptions(fieldCode); };
3219
3319
  BasicFormComponent.prototype.setFieldValue = function (fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); };
3320
+ BasicFormComponent.prototype.setFieldRequired = function (fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); };
3220
3321
  BasicFormComponent.prototype.setFieldErrorMessage = function (fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); };
3322
+ BasicFormComponent.prototype.setFieldError = function (code, message, type) {
3323
+ if (type === void 0) { type = 'error'; }
3324
+ return this.formStructure.setFieldError(code, message, type);
3325
+ };
3326
+ BasicFormComponent.prototype.setFieldIntrinsicErrorMessage = function (code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); };
3221
3327
  BasicFormComponent.prototype.setFieldOptions = function (fieldCode, optionsArray, idAttribute, nameAttribute) {
3222
3328
  return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
3223
3329
  };
@@ -3436,8 +3542,14 @@
3436
3542
  var formFields = this.formStructure.getFields();
3437
3543
  if (Array.isArray(formFields)) {
3438
3544
  formFields.forEach(function (field) {
3439
- field.editionFinish.subscribe(function (code) { return _this.startFieldValidation(code); });
3440
- field.editionPartial.subscribe(function (code) { return _this.startFieldInputValidation(code); });
3545
+ field.editionFinish.subscribe(function (event) {
3546
+ var code = event.code, intrinsicValidation = event.intrinsicValidation;
3547
+ _this.startFieldValidation(code, intrinsicValidation);
3548
+ });
3549
+ field.editionPartial.subscribe(function (event) {
3550
+ var code = event.code, intrinsicValidation = event.intrinsicValidation;
3551
+ _this.startFieldInputValidation(code, intrinsicValidation);
3552
+ });
3441
3553
  field.detailRequest.subscribe(function (code) { return _this.showFieldInfo(code); });
3442
3554
  });
3443
3555
  }
@@ -3904,7 +4016,8 @@
3904
4016
  _this.fieldValidationsFinish[fieldCode].push(callbackMethod);
3905
4017
  });
3906
4018
  };
3907
- BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode) {
4019
+ BasicFormComponent.prototype.startFieldInputValidation = function (fieldCode, intrinsicValidation) {
4020
+ if (intrinsicValidation === void 0) { intrinsicValidation = true; }
3908
4021
  return __awaiter(this, void 0, void 0, function () {
3909
4022
  var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_1, validationCallbacks_1_1, validationMethod, continueValidationPromise;
3910
4023
  var e_10, _g;
@@ -3943,7 +4056,8 @@
3943
4056
  });
3944
4057
  });
3945
4058
  };
3946
- BasicFormComponent.prototype.startFieldValidation = function (fieldCode) {
4059
+ BasicFormComponent.prototype.startFieldValidation = function (fieldCode, intrinsicValidation) {
4060
+ if (intrinsicValidation === void 0) { intrinsicValidation = true; }
3947
4061
  return __awaiter(this, void 0, void 0, function () {
3948
4062
  var fieldToValidate, validationCallbacks, clientValidationPromises, validationCallbacks_2, validationCallbacks_2_1, validationMethod, clientValidationPromise, clientValidationResults, continueValidation;
3949
4063
  var e_11, _g;
@@ -3951,7 +4065,7 @@
3951
4065
  switch (_h.label) {
3952
4066
  case 0:
3953
4067
  fieldToValidate = this.getField(fieldCode);
3954
- if (!fieldToValidate) {
4068
+ if (!fieldToValidate || !intrinsicValidation) {
3955
4069
  return [2 /*return*/];
3956
4070
  }
3957
4071
  fieldToValidate.setErrorMessage('');
@@ -3999,6 +4113,7 @@
3999
4113
  finish = true;
4000
4114
  validationResult = null;
4001
4115
  if (!fieldObj.backend) return [3 /*break*/, 2];
4116
+ fieldObj.validating = true;
4002
4117
  return [4 /*yield*/, this
4003
4118
  .requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode)];
4004
4119
  case 1:
@@ -4016,7 +4131,9 @@
4016
4131
  fieldObj.setErrorMessage(this.errorMessage);
4017
4132
  this.displayValidationServerError();
4018
4133
  _g.label = 5;
4019
- case 5: return [2 /*return*/];
4134
+ case 5:
4135
+ fieldObj.validating = false;
4136
+ return [2 /*return*/];
4020
4137
  }
4021
4138
  });
4022
4139
  });