Replies: 3 comments 6 replies
-
Need more context, don't even know what platform etc |
Beta Was this translation helpful? Give feedback.
-
For me it's Avalonia. You're right. I'll elaborate a bit :) Imagine that you have a Name field, usually handled by a TextBox.
If you add a rule requiring the field to be something, the user experience becomes a bit weird because, as soon as the view loads, the TextBox is surrounded by a red border and a validation error saying "Name cannot be empty" when the user hasn't even typed anything. What most users expect is not this, but to receive data validation errors once they click a button. Then, the validation is triggered, and remains active from then on. |
Beta Was this translation helpful? Give feedback.
-
I've run into the same issue and I'm kind of surprised the samples do not cover this. Ideally there would be some kind of way to clear all errors, giving you a clean state. Lastly in your submit method you can eagerly run a check on all of them using So in summary, I believe all we need is some kind of Right now I have an imperfect solution where I don't add rules until the user tries to submit the form. That way they only get feedback if anything is wrong after they've clicked Submit once, but at least they don't start off with a form full of error messages. private void ExecuteContinue()
{
if (!IsDirty)
{
this.ValidationRule(vm => vm.Name, s => !string.IsNullOrWhiteSpace(s), "Name cannot be empty.");
this.ValidationRule(vm => vm.Summary, s => !string.IsNullOrWhiteSpace(s), "Summary cannot be empty.");
this.ValidationRule(vm => vm.Description, s => !string.IsNullOrWhiteSpace(s), "Description cannot be empty.");
this.ValidationRule(vm => vm.Categories, Categories.ToObservableChangeSet().AutoRefresh(c => c.IsSelected).Filter(c => c.IsSelected).IsEmpty()
.CombineLatest(this.WhenAnyValue(vm => vm.IsDirty), (empty, dirty) => !dirty || !empty),
"At least one category must be selected"
);
IsDirty = true;
// The ValidationContext seems to update asynchronously, so stop and schedule a retry
Dispatcher.UIThread.Post(ExecuteContinue);
return;
}
if (!ValidationContext.GetIsValid())
return;
State.Name = Name;
State.Summary = Summary;
State.Description = Description;
} |
Beta Was this translation helpful? Give feedback.
-
Showing the error message like "Password can't be empty" with a red bounding box from the very beginning feels weird.
Is there any way to only show errors after the first "submit" of the data?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions