@fuentis/phoenix-ui 0.0.9-alpha.588 → 0.0.9-alpha.589
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.
|
@@ -3734,6 +3734,55 @@ function noDangerousCharsValidator() {
|
|
|
3734
3734
|
};
|
|
3735
3735
|
}
|
|
3736
3736
|
|
|
3737
|
+
var CompareOperatorType;
|
|
3738
|
+
(function (CompareOperatorType) {
|
|
3739
|
+
CompareOperatorType["LESS_OR_EQUAL"] = "LESS_OR_EQUAL";
|
|
3740
|
+
CompareOperatorType["LESS"] = "LESS";
|
|
3741
|
+
CompareOperatorType["EQUAL"] = "EQUAL";
|
|
3742
|
+
CompareOperatorType["MORE_OR_EQUAL"] = "MORE_OR_EQUAL";
|
|
3743
|
+
CompareOperatorType["MORE"] = "MORE";
|
|
3744
|
+
})(CompareOperatorType || (CompareOperatorType = {}));
|
|
3745
|
+
function dateCompareValidator(fieldToCompare, comparison, errMessage) {
|
|
3746
|
+
return (control) => {
|
|
3747
|
+
if (!control.parent)
|
|
3748
|
+
return null; // ako form group ne postoji
|
|
3749
|
+
const compareControl = control.parent.get(fieldToCompare);
|
|
3750
|
+
if (!compareControl)
|
|
3751
|
+
return null; // polje za poređenje ne postoji
|
|
3752
|
+
const controlValue = control.value ? new Date(control.value) : null;
|
|
3753
|
+
const compareValue = compareControl.value
|
|
3754
|
+
? new Date(compareControl.value)
|
|
3755
|
+
: null;
|
|
3756
|
+
if (!controlValue || !compareValue)
|
|
3757
|
+
return null; // nema vrednosti, ne validira
|
|
3758
|
+
let valid = true;
|
|
3759
|
+
switch (comparison) {
|
|
3760
|
+
case CompareOperatorType.LESS:
|
|
3761
|
+
valid = controlValue < compareValue;
|
|
3762
|
+
break;
|
|
3763
|
+
case CompareOperatorType.LESS_OR_EQUAL:
|
|
3764
|
+
valid = controlValue <= compareValue;
|
|
3765
|
+
break;
|
|
3766
|
+
case CompareOperatorType.EQUAL:
|
|
3767
|
+
valid = controlValue.getTime() === compareValue.getTime();
|
|
3768
|
+
break;
|
|
3769
|
+
case CompareOperatorType.MORE_OR_EQUAL:
|
|
3770
|
+
valid = controlValue >= compareValue;
|
|
3771
|
+
break;
|
|
3772
|
+
case CompareOperatorType.MORE:
|
|
3773
|
+
valid = controlValue > compareValue;
|
|
3774
|
+
break;
|
|
3775
|
+
}
|
|
3776
|
+
if (!valid) {
|
|
3777
|
+
return {
|
|
3778
|
+
dateCompare: errMessage ||
|
|
3779
|
+
`Datum ne zadovoljava uslov ${comparison} u odnosu na ${fieldToCompare}`,
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
return null; // validno
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
|
|
3737
3786
|
class MetaFormService {
|
|
3738
3787
|
router = inject(Router);
|
|
3739
3788
|
formEvent = new Subject();
|
|
@@ -3808,8 +3857,7 @@ class MetaFormAbstract {
|
|
|
3808
3857
|
onFormCancel = new EventEmitter();
|
|
3809
3858
|
formActive$;
|
|
3810
3859
|
formSub$;
|
|
3811
|
-
constructor(fb, metaService, translateService, http
|
|
3812
|
-
) {
|
|
3860
|
+
constructor(fb, metaService, translateService, http) {
|
|
3813
3861
|
this.fb = fb;
|
|
3814
3862
|
this.metaService = metaService;
|
|
3815
3863
|
this.translateService = translateService;
|
|
@@ -3823,10 +3871,7 @@ class MetaFormAbstract {
|
|
|
3823
3871
|
}
|
|
3824
3872
|
createForm(controls) {
|
|
3825
3873
|
controls?.forEach((control) => {
|
|
3826
|
-
this.metaForm.addControl(control.configuration?.key, this.fb.control(getFieldType(control)
|
|
3827
|
-
///updateOn: blur only for controls with async validators. If added for all each tab/step toggle removes form value. Check why
|
|
3828
|
-
// control.asyncValidators && { updateOn: 'blur' },
|
|
3829
|
-
));
|
|
3874
|
+
this.metaForm.addControl(control.configuration?.key, this.fb.control(getFieldType(control)));
|
|
3830
3875
|
//add validators
|
|
3831
3876
|
this.addControlValidators(control);
|
|
3832
3877
|
//disable non editable fields
|
|
@@ -3864,6 +3909,11 @@ class MetaFormAbstract {
|
|
|
3864
3909
|
validators.push(timePeriod(this.translateService.currentLang, control.validators.tpMin));
|
|
3865
3910
|
control.validators.dueDate && validators.push(startDueDateValidator);
|
|
3866
3911
|
}
|
|
3912
|
+
if (control.validators?.compare) {
|
|
3913
|
+
const compareConfig = control.validators.compare;
|
|
3914
|
+
validators.push(dateCompareValidator(compareConfig.fieldToCompare, // napomena: ispravi typo 'feildToCompare'
|
|
3915
|
+
compareConfig.comparisonOperator, compareConfig.errMessage));
|
|
3916
|
+
}
|
|
3867
3917
|
if (control?.mandatory) {
|
|
3868
3918
|
validators.push(Validators.required);
|
|
3869
3919
|
}
|
|
@@ -4386,6 +4436,7 @@ var ErrorType;
|
|
|
4386
4436
|
ErrorType["MAX"] = "max";
|
|
4387
4437
|
ErrorType["MIN"] = "min";
|
|
4388
4438
|
ErrorType["DANGEROUS_CHARS"] = "dangerousChars";
|
|
4439
|
+
ErrorType["DATE_COMPARE"] = "dateCompare";
|
|
4389
4440
|
})(ErrorType || (ErrorType = {}));
|
|
4390
4441
|
|
|
4391
4442
|
class InlineFieldError {
|
|
@@ -4437,6 +4488,7 @@ class InlineFieldError {
|
|
|
4437
4488
|
// return 'ENTRY OK';
|
|
4438
4489
|
// }
|
|
4439
4490
|
if (control?.errors) {
|
|
4491
|
+
console.log('error type', Object.keys(control.errors)[0]);
|
|
4440
4492
|
switch (Object.keys(control.errors)[0]) {
|
|
4441
4493
|
case ErrorType.REQUIRED:
|
|
4442
4494
|
return this.translateService.instant('VALIDATION_MESSAGE.THIS_FIELD_IS_REQUIRED');
|
|
@@ -4469,6 +4521,8 @@ class InlineFieldError {
|
|
|
4469
4521
|
return this.translateService.instant('VALIDATION_MESSAGE.VALUE_SHOULD_MATCH_TIMEPATTERN_LIMIT_MIN');
|
|
4470
4522
|
case ErrorType.BOTH_DATES:
|
|
4471
4523
|
return this.translateService.instant('VALIDATION_MESSAGE.BOTH_START_END_DATE_REQUIRED');
|
|
4524
|
+
case ErrorType.DATE_COMPARE:
|
|
4525
|
+
return this.translateService.instant(control.errors['dateCompare']);
|
|
4472
4526
|
// add more cases for other validators as needed
|
|
4473
4527
|
case ErrorType.PATTERN:
|
|
4474
4528
|
const re = '^(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?$';
|