tuain-ng-forms-lib 14.0.7 → 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.
- package/esm2020/lib/classes/forms/field.mjs +46 -7
- package/esm2020/lib/components/forms/basic-form.mjs +1 -3
- package/fesm2015/tuain-ng-forms-lib.mjs +48 -12
- package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -1
- package/fesm2020/tuain-ng-forms-lib.mjs +45 -8
- package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -1
- package/lib/classes/forms/field.d.ts +5 -2
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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') {
|
|
@@ -668,15 +700,22 @@ class FieldDescriptor extends FormElement {
|
|
|
668
700
|
get value() { return this.getValue(); }
|
|
669
701
|
set value(newValue) { this.setValue(newValue); }
|
|
670
702
|
notifyEditionPartial() {
|
|
703
|
+
this.resetError();
|
|
671
704
|
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: true });
|
|
672
705
|
}
|
|
673
706
|
notifyEditionFinish() {
|
|
674
|
-
let intrinsicValidation = true;
|
|
675
|
-
const fieldDefaultFormat = this._formConfig.fieldTypesPatterns?.[this.fieldType] ?? null;
|
|
676
707
|
const fieldValue = this.getValue();
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
708
|
+
this.resetError();
|
|
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
|
+
}
|
|
680
719
|
if (!intrinsicValidation) {
|
|
681
720
|
this.setError('99', this._intrinsicErrorMessage);
|
|
682
721
|
}
|
|
@@ -2924,7 +2963,6 @@ class BasicFormComponent {
|
|
|
2924
2963
|
if (!fieldToValidate) {
|
|
2925
2964
|
return false;
|
|
2926
2965
|
}
|
|
2927
|
-
fieldToValidate.resetError();
|
|
2928
2966
|
const validationCallbacks = this._fieldInputValidation[fieldCode];
|
|
2929
2967
|
if (validationCallbacks) {
|
|
2930
2968
|
const clientValidationPromises = [];
|
|
@@ -2942,7 +2980,6 @@ class BasicFormComponent {
|
|
|
2942
2980
|
if (!fieldToValidate) {
|
|
2943
2981
|
return;
|
|
2944
2982
|
}
|
|
2945
|
-
fieldToValidate.resetError();
|
|
2946
2983
|
const validationCallbacks = this._fieldValidationsStart[fieldCode];
|
|
2947
2984
|
if (validationCallbacks) {
|
|
2948
2985
|
const clientValidationPromises = [];
|