Skip to content

useCollectionItemValidators

Andrei Fangli edited this page Jun 5, 2021 · 2 revisions
API / useCollectionItemValidators<TItem, TValidatableViewModel> hook

Registers and applies the provided validators to each item. The collection and validators are part of the dependencies.

The validators are applied one after the other until the first one returns an error message (a value different from undefined).

Whenever a property has changed (except for error, isValid and isInvalid) on the validatable, a new validation is performed just on that item and not the entire collection. This is useful when items have individual validation rules (e.g.: required value).

function useCollectionItemValidators<TItem, TValidatableViewModel extends IValidatable & INotifyPropertiesChanged>(collection: IReadOnlyObservableCollection<TItem>, selector: ValidatableSelectorCallback<TItem, TValidatableViewModel>, validators: readonly (CollectionItemValidatorCallback<TValidatableViewModel, TItem> | undefined)[]): void
function useCollectionItemValidators<TItem, TValidatableViewModel extends IValidatable & INotifyPropertiesChanged>(collection: IReadOnlyObservableCollection<TItem>, selector: ValidationConfigSelectorCallback<TItem, TValidatableViewModel>, validators: readonly (CollectionItemValidatorCallback<TValidatableViewModel, TItem> | undefined)[]): void

Template Parameters

  • TItem: the type of object the collection contains.
  • TValidatableViewModel: the type of validatable objects that are registered for validation. Must implement IValidatable and INotifyPropertiesChanged.

Parameters

  • collection: IReadOnlyObservableCollection<TItem>, the collection to watch, validators are registered for each item. When the collection changes all subscriptions and unsubscriptions are done accordingly.
    • selector: ValidatableSelectorCallback<TItem, TValidatableViewModel>, a callback that selects a validatable from each item. The returned validatable or target and triggers must be the same for each item in particular in order to properly unsubscribe the event handlers.
    • selector: ValidationConfigSelectorCallback<TItem, TValidatableViewModel>, a callback that selects a validation config from each item. The returned validatable or target and triggers must be the same for each item in particular in order to properly unsubscribe the event handlers.
  • validators: readonly Array<CollectionItemValidatorCallback<TValidatableViewModel, TItem>>, the callback validators that handle validation for each item.
Clone this wiki locally