tuain-ng-forms-lib 14.0.8 → 14.0.9

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.
@@ -599,6 +599,30 @@ class FieldDescriptor extends FormElement {
599
599
  this._editionPartial = new Subject();
600
600
  this._detailRequest = new Subject();
601
601
  this._attributeChange = new Subject();
602
+ this.validateOnServer = false;
603
+ this._focus = false;
604
+ this._maxLength = 0;
605
+ this._minLength = 0;
606
+ this._onValidation = false;
607
+ this._intrinsicErrorMessage = '';
608
+ this.fieldCode = '';
609
+ this.fieldInfo = '';
610
+ this.defaultValue = '';
611
+ this.defaultEditable = false;
612
+ this.visibleLabel = false;
613
+ this.fieldRequired = false;
614
+ this.hasChanged = false;
615
+ this.outputOnly = false;
616
+ this.captureType = '';
617
+ this.fieldTitle = '';
618
+ this.fieldType = '';
619
+ this.fieldAlignment = '';
620
+ this.fieldFormat = null;
621
+ this.tooltipText = '';
622
+ this.errorType = '';
623
+ this.errorCode = '';
624
+ this.errorMessage = '';
625
+ this.fieldOptions = null;
602
626
  this.elementType = elementTypes.field;
603
627
  const fld = (inputFieldReceived) ? inputFieldReceived : {};
604
628
  this.setAttr(fldAttr.code, fld.fieldCode);
@@ -633,7 +657,9 @@ class FieldDescriptor extends FormElement {
633
657
  this.setAttr(fldAttr.outputOnly, fld.outputOnly ?? false);
634
658
  const maxLength = fld.maxLength ?? (this.captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
635
659
  this.setAttr(fldAttr.maxLength, maxLength);
636
- this.setAttr(fldAttr.intrinsicErrorMessage, this._formConfig.fieldTypeErrMsg[this.fieldType] ?? this._formConfig.fieldTypeErrMsg.DEFAULT);
660
+ const intrinsicErrorMessage = this._formConfig?.fieldValidations?.[this.fieldType]?.message
661
+ ?? this._formConfig?.fieldValidations?.DEFAULT?.message ?? '';
662
+ this.setAttr(fldAttr.intrinsicErrorMessage, intrinsicErrorMessage);
637
663
  this.setEditable(fld.editable ?? true);
638
664
  this.setVisibleLabel(fld.visibleLabel ?? true);
639
665
  this.setVisibility(fld.visible);
@@ -656,6 +682,12 @@ class FieldDescriptor extends FormElement {
656
682
  setRequired(required) { this.required = required; }
657
683
  get required() { return this.fieldRequired; }
658
684
  set required(required) { this.setAttr(fldAttr.required, required ?? false); }
685
+ get minLength() { return (this._minLength > 0) ? this._minLength.toString() : ''; }
686
+ set minLength(requiredMinLength) {
687
+ let newMinLength = +requiredMinLength;
688
+ newMinLength = (isNaN(newMinLength) || newMinLength < 0) ? 0 : newMinLength;
689
+ this.setAttr(fldAttr.maxLength, +requiredMinLength);
690
+ }
659
691
  get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
660
692
  set maxLength(requiredMaxLength) {
661
693
  if (typeof requiredMaxLength === 'string') {
@@ -672,13 +704,18 @@ class FieldDescriptor extends FormElement {
672
704
  this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: true });
673
705
  }
674
706
  notifyEditionFinish() {
675
- let intrinsicValidation = true;
676
- const fieldDefaultFormat = this._formConfig.fieldTypesPatterns?.[this.fieldType] ?? null;
677
707
  const fieldValue = this.getValue();
678
708
  this.resetError();
679
- if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
680
- intrinsicValidation = (fieldDefaultFormat?.test(fieldValue) ?? true)
681
- && (this.fieldFormat?.test(fieldValue) ?? true);
709
+ const { type, validation, message } = this._formConfig.fieldValidations?.[this.fieldType] ?? {};
710
+ let intrinsicValidation = true;
711
+ if (fieldValue && (validation || this.fieldFormat)) {
712
+ if (type === 'regexp') {
713
+ intrinsicValidation = (validation?.test(fieldValue) ?? true)
714
+ && (this.fieldFormat?.test(fieldValue) ?? true);
715
+ }
716
+ else if (type === 'function' && typeof fieldValue === 'function') {
717
+ intrinsicValidation = validation(fieldValue);
718
+ }
682
719
  if (!intrinsicValidation) {
683
720
  this.setError('99', this._intrinsicErrorMessage);
684
721
  }