Skip to content

registerCollectionItemValidators

Andrei Fangli edited this page Jun 5, 2021 · 4 revisions
API / registerCollectionItemValidators<TItem, TValidatableViewModel> function

Registers and applies the provided validators to each item and returns a clean-up callback.

The validators are applies 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 registerCollectionItemValidators<TItem, TValidatableViewModel extends IValidatable & INotifyPropertiesChanged>(collection: IReadOnlyObservableCollection<TItem>, selector: ValidatableSelectorCallback<TItem, TValidatableViewModel>, validators: readonly CollectionItemValidatorCallback<TValidatableViewModel, TItem>[]): UnsubscribeCallback
function registerCollectionItemValidators<TItem, TValidatableViewModel extends IValidatable & INotifyPropertiesChanged>(collection: IReadOnlyObservableCollection<TItem>, selector: ValidationConfigSelectorCallback<TItem, TValidatableViewModel>, validators: readonly CollectionItemValidatorCallback<TValidatableViewModel, TItem>[]): UnsubscribeCallback

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 value 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 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.

Returns a clean-up callback that unsubscribes all event registrations.

Clone this wiki locally