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
I have a viewmodel which needs to call an external service to validate a property. As a contrived example:
[ObservableProperty]
[Required(ErrorMessage = "Please enter the reservation date/time")]
private DateTimeOffset? _reservationTime;
private async Task<ValidationResult> ValidateReservation()
{
if (_reservationTime is not {} reservationTime) return ValidationResult.Success;
var result = await MyService.ValidateReservation(reservationTime);
if (result.CanMakeReservation) return ValidationResult.Success;
return new(result.ErrorMessage, [nameof(ReservationTime)]);
}
However, I can't see any simple way to implement that using the ObservableValidator class. There doesn't seem to be any support for async validation in the System.ComponentModel.DataAnnotations, and I can't see any way for a validation task to add a validation error message for a property.
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
Uh oh!
There was an error while loading. Please reload this page.
-
I have a viewmodel which needs to call an external service to validate a property. As a contrived example:
However, I can't see any simple way to implement that using the
ObservableValidator
class. There doesn't seem to be any support forasync
validation in theSystem.ComponentModel.DataAnnotations
, and I can't see any way for a validation task to add a validation error message for a property.The best I can come up with is a horrible hack:
Have I missed something obvious?
Beta Was this translation helpful? Give feedback.
All reactions