@ascentgl/ads-ui 21.17.4 → 21.19.0
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.
|
@@ -2409,7 +2409,10 @@ class AbstractBaseComponent {
|
|
|
2409
2409
|
.subscribe((event) => {
|
|
2410
2410
|
if (event.touched) {
|
|
2411
2411
|
this.syncState();
|
|
2412
|
-
|
|
2412
|
+
// Avoid triggering validators for empty values when configured.
|
|
2413
|
+
if (!this.skipValidationWhenEmpty || !this.isEmptyValue(this.valueControl.value)) {
|
|
2414
|
+
this.displayControl.updateValueAndValidity({ emitEvent: false });
|
|
2415
|
+
}
|
|
2413
2416
|
}
|
|
2414
2417
|
});
|
|
2415
2418
|
this.destroyRef.onDestroy(() => subscription.unsubscribe());
|
|
@@ -2424,6 +2427,11 @@ class AbstractBaseComponent {
|
|
|
2424
2427
|
}
|
|
2425
2428
|
constructor() {
|
|
2426
2429
|
this._isStaticFooter = inject(ADS_UI_CONFIG, { optional: true })?.staticFormFieldFooter;
|
|
2430
|
+
/**
|
|
2431
|
+
* If true, validators won't be triggered when the field value is empty (null/undefined/"").
|
|
2432
|
+
* Useful for cases where validation should only run once the user provides a value.
|
|
2433
|
+
*/
|
|
2434
|
+
this.skipValidationWhenEmpty = false;
|
|
2427
2435
|
/** @ignore */
|
|
2428
2436
|
this.displayControl = new FormControl();
|
|
2429
2437
|
/** If true, invalid field will immediately become dirty to display the error */
|
|
@@ -2527,12 +2535,28 @@ class AbstractBaseComponent {
|
|
|
2527
2535
|
else if (this.displayControl.untouched) {
|
|
2528
2536
|
this.displayControl.markAsTouched();
|
|
2529
2537
|
}
|
|
2538
|
+
// If configured, treat empty value as "no validation" state.
|
|
2539
|
+
if (this.skipValidationWhenEmpty && this.isEmptyValue(this.valueControl.value)) {
|
|
2540
|
+
if (this.valueControl.errors) {
|
|
2541
|
+
this.valueControl.setErrors(null);
|
|
2542
|
+
}
|
|
2543
|
+
if (this.displayControl.errors) {
|
|
2544
|
+
this.displayControl.setErrors(null);
|
|
2545
|
+
}
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2530
2548
|
if (this.valueControl.valid !== this.displayControl.valid) {
|
|
2531
2549
|
this.displayControl.setErrors(this.valueControl.errors);
|
|
2532
2550
|
}
|
|
2533
2551
|
}
|
|
2534
2552
|
/** @ignore */
|
|
2553
|
+
isEmptyValue(value) {
|
|
2554
|
+
return value === null || value === undefined || value === '';
|
|
2555
|
+
}
|
|
2556
|
+
/** @ignore */
|
|
2535
2557
|
canShowError() {
|
|
2558
|
+
if (this.skipValidationWhenEmpty && this.isEmptyValue(this.valueControl.value))
|
|
2559
|
+
return false;
|
|
2536
2560
|
return !!this.valueControl.errors && (this.valueControl.touched || this.immediateValidation);
|
|
2537
2561
|
}
|
|
2538
2562
|
/** @ignore */
|
|
@@ -2540,11 +2564,13 @@ class AbstractBaseComponent {
|
|
|
2540
2564
|
return !this.valueControl.errors && this.valueControl.touched && !!this.successMessage;
|
|
2541
2565
|
}
|
|
2542
2566
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AbstractBaseComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2543
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: AbstractBaseComponent, isStandalone: true, inputs: { control: "control", immediateValidation: "immediateValidation", errorMessages: "errorMessages", hint: "hint", successMessage: "successMessage", id: "id", label: "label", showFooter: "showFooter", width: "width" }, usesOnChanges: true, ngImport: i0 }); }
|
|
2567
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: AbstractBaseComponent, isStandalone: true, inputs: { skipValidationWhenEmpty: "skipValidationWhenEmpty", control: "control", immediateValidation: "immediateValidation", errorMessages: "errorMessages", hint: "hint", successMessage: "successMessage", id: "id", label: "label", showFooter: "showFooter", width: "width" }, usesOnChanges: true, ngImport: i0 }); }
|
|
2544
2568
|
}
|
|
2545
2569
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AbstractBaseComponent, decorators: [{
|
|
2546
2570
|
type: Directive
|
|
2547
|
-
}], ctorParameters: () => [], propDecorators: {
|
|
2571
|
+
}], ctorParameters: () => [], propDecorators: { skipValidationWhenEmpty: [{
|
|
2572
|
+
type: Input
|
|
2573
|
+
}], control: [{
|
|
2548
2574
|
type: Input
|
|
2549
2575
|
}], immediateValidation: [{
|
|
2550
2576
|
type: Input
|