You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is currently not possible to do validation and get all the errors to display them to the user.
I am using the FluentModelValidator<> implementation from the documentation.
My use case is a popup dialog with several interdependent input fields, where the Save button shall revalidate the form and display a summary of validation errors if there are any.
It is currently not possible to do this using singular method calls:
Call this.ValidateAsync() in the ViewModel.
This uses the underlying INotifyDataErrorInfo interface and causes ValidatingModelBase to collect the errors nicely, but I have no way of just getting all errors. There is IValidationModel.GetErrors(string), but I'd have to know all the property names, loop, ...
Call this.Validator.ValidateAllPropertiesAsync() in the ViewModel.
I get all errors, but since this cannot raise INotifyDataErrorInfo events, the controls of the View (which might want to react by e.g. displaying a decorator) are not notified.
Any workaround is either impossible or has serious code smells:
Calling both of the above methods. I get error string and decorators, but I'm running all validations twice.
Subscribing to INotifyDataErrorInfo - cumbersome and duplicate work, since ValidatingModelBase already does all that work.
Using IModelValidator<T>.ValidateAllPropertiesAsync. in my ViewModel, then propagating the result myself via ViewModelBase.RecordPropertyError(...) - dupliate work, but the least added boilerplate code
Ideally, I would love to have an extension method ValidatingModelBase.ValidateAllPropertiesAsync() which raises INotifyDataErrorInfo events and returns the errors like the IModelValidator<T>.ValidateAllPropertiesAsync()., so I get the combination of 1. and 2. above.
Sadly, I cannot implement it as extension method because ValidatingModelBase.Validator has a protected getter.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
It is currently not possible to do validation and get all the errors to display them to the user.
I am using the
FluentModelValidator<>
implementation from the documentation.My use case is a popup dialog with several interdependent input fields, where the
Save
button shall revalidate the form and display a summary of validation errors if there are any.It is currently not possible to do this using singular method calls:
Call
this.ValidateAsync()
in the ViewModel.This uses the underlying
INotifyDataErrorInfo
interface and causesValidatingModelBase
to collect the errors nicely, but I have no way of just getting all errors. There isIValidationModel.GetErrors(string)
, but I'd have to know all the property names, loop, ...Call
this.Validator.ValidateAllPropertiesAsync()
in the ViewModel.I get all errors, but since this cannot raise
INotifyDataErrorInfo
events, the controls of the View (which might want to react by e.g. displaying a decorator) are not notified.Any workaround is either impossible or has serious code smells:
INotifyDataErrorInfo
- cumbersome and duplicate work, sinceValidatingModelBase
already does all that work.IModelValidator<T>.ValidateAllPropertiesAsync.
in my ViewModel, then propagating the result myself viaViewModelBase.RecordPropertyError(...)
- dupliate work, but the least added boilerplate codeIdeally, I would love to have an extension method
ValidatingModelBase.ValidateAllPropertiesAsync()
which raisesINotifyDataErrorInfo
events and returns the errors like theIModelValidator<T>.ValidateAllPropertiesAsync().
, so I get the combination of 1. and 2. above.Sadly, I cannot implement it as extension method because
ValidatingModelBase.Validator
has a protected getter.Beta Was this translation helpful? Give feedback.
All reactions