tuain-ng-forms-lib 0.12.19 → 0.12.23

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.
@@ -871,17 +871,17 @@ class RecordTable extends FormElement {
871
871
  if (!this.sorting.columnName || !this.sorting.direction) {
872
872
  return;
873
873
  }
874
- this.tableRecords = this.tableRecords
875
- .sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
874
+ this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
875
+ this.updateVisibleRecords();
876
876
  }
877
877
  recordCompare(recordA, recordB, columnCompare, direction) {
878
878
  const recordAColumn = recordA.getFieldValue(columnCompare);
879
879
  const recordBColumn = recordB.getFieldValue(columnCompare);
880
880
  let result = 0;
881
- if (recordAColumn.fieldValue < recordBColumn.fieldValue) {
881
+ if (recordAColumn < recordBColumn) {
882
882
  result = -1;
883
883
  }
884
- else if (recordAColumn.fieldValue > recordBColumn.fieldValue) {
884
+ else if (recordAColumn > recordBColumn) {
885
885
  result = 1;
886
886
  }
887
887
  return direction === componentConstants.TABLE_SORT_ASCENDING ? result : -result;
@@ -1349,11 +1349,39 @@ const FIELD_ERR_MSG = 'errorMessage';
1349
1349
  const FIELD_TOOLTIP = 'tooltipText';
1350
1350
  const FIELD_INFO = 'info';
1351
1351
  const FIELD_EDITABLE = 'editable';
1352
+ const FIELD_TYPES = {
1353
+ array: 'ARRAY',
1354
+ check: 'CHECK',
1355
+ date: 'DATE',
1356
+ daterange: 'DATERANGE',
1357
+ time: 'TIME',
1358
+ timerange: 'TIMERANGE',
1359
+ map: 'MAP',
1360
+ number: 'NUMBER',
1361
+ decimal: 'DECIMAL',
1362
+ currency: 'CURRENCY',
1363
+ select: 'SELECT',
1364
+ typeahead: 'TYPEAHEAD',
1365
+ text: 'TEXT',
1366
+ password: 'PASSWORD',
1367
+ label: 'LABEL',
1368
+ html: 'HTML',
1369
+ title: 'TITLE',
1370
+ message: 'MESSAGE',
1371
+ link: 'LINK',
1372
+ warning: 'WARNING',
1373
+ avatar: 'AVATAR',
1374
+ email: 'EMAIL',
1375
+ phone: 'PHONE',
1376
+ };
1377
+ const FIELD_TYPES_FORMATS = {
1378
+ EMAIL: new RegExp('^\\w+([\\.-]?\\w+)@\\w+([\\.-]?\\w+)(\\.\\w{2,3})+$'),
1379
+ };
1352
1380
  const STD_MAX_LENGTH = 50;
1353
1381
  const BIG_MAX_LENGTH = 500;
1354
1382
  class FieldDescriptor extends FormElement {
1355
1383
  constructor(inputFieldReceived) {
1356
- var _a, _b, _c, _d, _e, _f, _g;
1384
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1357
1385
  super(inputFieldReceived);
1358
1386
  this._editionFinish = new Subject();
1359
1387
  this._editionPartial = new Subject();
@@ -1371,7 +1399,12 @@ class FieldDescriptor extends FormElement {
1371
1399
  const defaultTypeAlignment = (tableFieldStyles[this.fieldType] != null) ? tableFieldStyles[this.fieldType]['text-align'] : 'left';
1372
1400
  this.fieldAlignment = (fieldReceived.alignment != null) ? fieldReceived.alignment.toLowerCase() : defaultTypeAlignment;
1373
1401
  this.fieldInfo = fieldReceived.info || '';
1374
- this.fieldFormat = fieldReceived.format || '';
1402
+ try {
1403
+ this.fieldFormat = (fieldReceived.format) ? new RegExp(fieldReceived.format) : null;
1404
+ }
1405
+ catch (e) {
1406
+ this.fieldFormat = null;
1407
+ }
1375
1408
  this.validateOnServer = (_c = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.serverAction) !== null && _c !== void 0 ? _c : false;
1376
1409
  this.customAttributes = (_d = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.customAttributes) !== null && _d !== void 0 ? _d : null;
1377
1410
  this.setVisibility(fieldReceived.visible);
@@ -1380,14 +1413,21 @@ class FieldDescriptor extends FormElement {
1380
1413
  this.defaultEditable = this.enabled;
1381
1414
  this.fieldRequired = (_f = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.required) !== null && _f !== void 0 ? _f : false;
1382
1415
  this.errorMessage = fieldReceived.errorMessage || '';
1383
- this.errorCode = fieldReceived.errorCode || '00';
1384
- this.outputOnly = (_g = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _g !== void 0 ? _g : false;
1416
+ this.errorCode = (_g = fieldReceived.errorCode) !== null && _g !== void 0 ? _g : '00';
1417
+ this.outputOnly = (_h = fieldReceived === null || fieldReceived === void 0 ? void 0 : fieldReceived.outputOnly) !== null && _h !== void 0 ? _h : false;
1385
1418
  this.setFieldOptions(fieldReceived.fieldOptions);
1419
+ this._intrinsicErrorMessage = (this.fieldType === FIELD_TYPES.email)
1420
+ ? `El valor de ${this.fieldTitle} no corresponde a un correo válido`
1421
+ : `El valor de ${this.fieldTitle} no se ajusta al formato establecido`;
1386
1422
  }
1387
1423
  get name() { return this.fieldCode; }
1388
1424
  get editionFinish() { return this._editionFinish; }
1389
1425
  get editionPartial() { return this._editionPartial; }
1390
1426
  get detailRequest() { return this._detailRequest; }
1427
+ get validating() { return this._onValidation; }
1428
+ set validating(isValidating) { this._onValidation = isValidating; }
1429
+ setIntrinsicErrorMessage(message) { this._intrinsicErrorMessage = message; }
1430
+ set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
1391
1431
  get fieldValue() { return this.getValue(); }
1392
1432
  get required() { return this.fieldRequired; }
1393
1433
  set required(required) { this.fieldRequired = required !== null && required !== void 0 ? required : false; }
@@ -1402,9 +1442,27 @@ class FieldDescriptor extends FormElement {
1402
1442
  }
1403
1443
  get value() { return this.getValue(); }
1404
1444
  set value(newValue) { this.setValue(newValue); }
1405
- notifyEditionPartial() { this._editionPartial.next(this.fieldCode); }
1406
- notifyEditionFinish() { this._editionFinish.next(this.fieldCode); }
1407
- notifyEditionDetailRequest() { this._detailRequest.next(this.fieldCode); }
1445
+ notifyEditionPartial() {
1446
+ const intrinsicValidation = true;
1447
+ this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
1448
+ }
1449
+ notifyEditionFinish() {
1450
+ var _a, _b, _c, _d;
1451
+ let intrinsicValidation = true;
1452
+ 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;
1453
+ const fieldValue = this.getValue();
1454
+ if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
1455
+ intrinsicValidation = ((_b = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _b !== void 0 ? _b : true)
1456
+ && ((_d = (_c = this.fieldFormat) === null || _c === void 0 ? void 0 : _c.test(fieldValue)) !== null && _d !== void 0 ? _d : true);
1457
+ if (!intrinsicValidation) {
1458
+ this.setError('99', this._intrinsicErrorMessage);
1459
+ }
1460
+ }
1461
+ this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
1462
+ }
1463
+ notifyEditionDetailRequest() {
1464
+ this._detailRequest.next(this.fieldCode);
1465
+ }
1408
1466
  showLabel() { this.visibleLabel = true; }
1409
1467
  hideLabel() { this.visibleLabel = false; }
1410
1468
  changed() { this.hasChanged = true; }
@@ -1414,11 +1472,30 @@ class FieldDescriptor extends FormElement {
1414
1472
  get backend() { return this.validateOnServer; }
1415
1473
  setVisibleLabel(visibleLabel) { this.visibleLabel = visibleLabel; }
1416
1474
  setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
1417
- isEmpty() { return this.getValue() === '' || this.getValue() === undefined || this.getValue() === null; }
1418
- getErrorCode() { return this.errorCode; }
1419
- setErrorCode(code) { this.errorCode = code; }
1420
- getErrorMessage() { return this.errorMessage; }
1421
- setErrorMessage(msg) { this.errorMessage = msg; }
1475
+ setError(code, message, type = 'error') {
1476
+ this.errorType = (code === '00') ? '' : type;
1477
+ this.errorCode = code;
1478
+ this.errorMessage = message;
1479
+ }
1480
+ getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
1481
+ get error() { return this.getError(); }
1482
+ set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type); }
1483
+ getErrorCode() { return this.getError().code; }
1484
+ setErrorCode(code) { this.setError(code, this.errorMessage); }
1485
+ getErrorMessage() { return this.getError().message; }
1486
+ setErrorMessage(msg) { this.setError(this.errorCode, msg); }
1487
+ isEmpty() {
1488
+ const fieldCurrentValue = this.getValue();
1489
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
1490
+ return true;
1491
+ }
1492
+ if ((this.fieldType === FIELD_TYPES.array || this.fieldType === FIELD_TYPES.phone)
1493
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
1494
+ return true;
1495
+ }
1496
+ ;
1497
+ return fieldCurrentValue === '';
1498
+ }
1422
1499
  getValue() {
1423
1500
  var _a;
1424
1501
  switch (this.fieldType) {
@@ -1976,6 +2053,14 @@ class FormStructureAndData {
1976
2053
  const fieldObject = this.getFieldObject(fieldCode);
1977
2054
  return (fieldObject) ? fieldObject.setValue(fieldValue) : null;
1978
2055
  }
2056
+ setFieldError(code, message, type = 'error') {
2057
+ const fieldObject = this.getFieldObject(code);
2058
+ return (fieldObject) ? fieldObject.setError(code, message, type) : null;
2059
+ }
2060
+ setFieldIntrinsicErrorMessage(code, message) {
2061
+ const fieldObject = this.getFieldObject(code);
2062
+ return (fieldObject) ? fieldObject.setIntrinsicErrorMessage(message) : null;
2063
+ }
1979
2064
  setFieldRequired(fieldCode, required) {
1980
2065
  const fieldObject = this.getFieldObject(fieldCode);
1981
2066
  return (fieldObject) ? fieldObject.required = required : null;
@@ -2356,6 +2441,8 @@ class BasicFormComponent {
2356
2441
  setFieldValue(fieldCode, fieldValue) { return this.formStructure.setFieldValue(fieldCode, fieldValue); }
2357
2442
  setFieldRequired(fieldCode, required) { return this.formStructure.setFieldRequired(fieldCode, required); }
2358
2443
  setFieldErrorMessage(fieldCode, errorMessage) { return this.formStructure.setFieldErrorMessage(fieldCode, errorMessage); }
2444
+ setFieldError(code, message, type = 'error') { return this.formStructure.setFieldError(code, message, type); }
2445
+ setFieldIntrinsicErrorMessage(code, message) { return this.formStructure.setFieldIntrinsicErrorMessage(code, message); }
2359
2446
  setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute) {
2360
2447
  return this.formStructure.setFieldOptions(fieldCode, optionsArray, idAttribute, nameAttribute);
2361
2448
  }
@@ -2548,8 +2635,14 @@ class BasicFormComponent {
2548
2635
  const formFields = this.formStructure.getFields();
2549
2636
  if (Array.isArray(formFields)) {
2550
2637
  formFields.forEach(field => {
2551
- field.editionFinish.subscribe(code => this.startFieldValidation(code));
2552
- field.editionPartial.subscribe(code => this.startFieldInputValidation(code));
2638
+ field.editionFinish.subscribe(event => {
2639
+ const { code, intrinsicValidation } = event;
2640
+ this.startFieldValidation(code, intrinsicValidation);
2641
+ });
2642
+ field.editionPartial.subscribe(event => {
2643
+ const { code, intrinsicValidation } = event;
2644
+ this.startFieldInputValidation(code, intrinsicValidation);
2645
+ });
2553
2646
  field.detailRequest.subscribe(code => this.showFieldInfo(code));
2554
2647
  });
2555
2648
  }
@@ -2860,7 +2953,7 @@ class BasicFormComponent {
2860
2953
  this.fieldValidationsFinish[fieldCode].push(callbackMethod);
2861
2954
  });
2862
2955
  }
2863
- startFieldInputValidation(fieldCode) {
2956
+ startFieldInputValidation(fieldCode, intrinsicValidation = true) {
2864
2957
  return __awaiter(this, void 0, void 0, function* () {
2865
2958
  const fieldToValidate = this.getFieldObject(fieldCode);
2866
2959
  if (!fieldToValidate) {
@@ -2879,10 +2972,10 @@ class BasicFormComponent {
2879
2972
  }
2880
2973
  });
2881
2974
  }
2882
- startFieldValidation(fieldCode) {
2975
+ startFieldValidation(fieldCode, intrinsicValidation = true) {
2883
2976
  return __awaiter(this, void 0, void 0, function* () {
2884
2977
  const fieldToValidate = this.getField(fieldCode);
2885
- if (!fieldToValidate) {
2978
+ if (!fieldToValidate || !intrinsicValidation) {
2886
2979
  return;
2887
2980
  }
2888
2981
  fieldToValidate.setErrorMessage('');
@@ -2910,6 +3003,7 @@ class BasicFormComponent {
2910
3003
  let finish = true;
2911
3004
  let validationResult = null;
2912
3005
  if (fieldObj.backend) {
3006
+ fieldObj.validating = true;
2913
3007
  validationResult = yield this
2914
3008
  .requestFormAction(componentConstants.FORMACTION_VALIDATE, fieldObj.fieldCode);
2915
3009
  finish = !this.errorOccured();
@@ -2922,6 +3016,7 @@ class BasicFormComponent {
2922
3016
  fieldObj.setErrorMessage(this.errorMessage);
2923
3017
  this.displayValidationServerError();
2924
3018
  }
3019
+ fieldObj.validating = false;
2925
3020
  });
2926
3021
  }
2927
3022
  finishFieldValidation(fieldObject, validationResult) {