fixed unlinked categories validation

This commit is contained in:
Flaminel
2025-06-22 22:03:42 +03:00
parent 910633a413
commit 96dc8bec51
2 changed files with 23 additions and 1 deletions

View File

@@ -248,6 +248,7 @@
>
</p-autocomplete>
</div>
<small *ngIf="hasUnlinkedCategoriesError()" class="p-error">At least one category is required when unlinked download handling is enabled</small>
<small class="form-helper-text">Categories to check for unlinked downloads</small>
</div>
</div>

View File

@@ -139,7 +139,7 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent
unlinkedUseTag: [{ value: false, disabled: true }],
unlinkedIgnoredRootDir: [{ value: '', disabled: true }],
unlinkedCategories: [{ value: [], disabled: true }]
});
}, { validators: this.validateUnlinkedCategories });
// Load the current configuration
effect(() => {
@@ -199,6 +199,20 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent
return null;
}
/**
* Custom validator for unlinked categories - requires categories when unlinked handling is enabled
*/
private validateUnlinkedCategories(group: FormGroup): ValidationErrors | null {
const unlinkedEnabled = group.get('unlinkedEnabled')?.value;
const unlinkedCategories = group.get('unlinkedCategories')?.value;
if (unlinkedEnabled && (!unlinkedCategories || unlinkedCategories.length === 0)) {
return { unlinkedCategoriesRequired: true };
}
return null;
}
/**
* Helper method to get a category control as FormGroup for the template
*/
@@ -592,6 +606,13 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent
return control ? control.touched && control.hasError(errorName) : false;
}
/**
* Check if the form has the unlinked categories validation error
*/
hasUnlinkedCategoriesError(): boolean {
return this.downloadCleanerForm.touched && this.downloadCleanerForm.hasError('unlinkedCategoriesRequired');
}
/**
* Get schedule value options based on the current schedule unit type
*/