pglazkov / MvvmValidation

Lightweight library that helps reduce boilerplate when implementing validation in XAML MVVM applications
MIT License
167 stars 31 forks source link

Inconsistent state while async validation #19

Open abgenullt opened 5 years ago

abgenullt commented 5 years ago

Hi, at first, thanks for this great library!

But if your UserRegistrationService (In your example) takes, like 1, 2 or more seconds to run, the form is in an false valid or invalid state. The User may edit the username while validating or just press the "submit" button.

Maybe there should be a state object, that you will get by adding a async rule. You could bind to that and disable the text box or do whatever you want. Or the validation state could be set to invalid before execute an async rule.

Regards

abgenullt

pglazkov commented 5 years ago

Hi abgenullt,

Thanks for taking the time to make this bug report. Indeed, I see the issue. However your suggestion to make the state invalid might not be a good solution because it is an incorrect state and a validation error might be shown to the user while in fact there is no error.

One of the solution that comes to mind would be to block the GetResult call if the state is "unknown" that is while rules are being evaluated. However, simply blocking the thread might possibly lead to deadlocks, so it might not be the best solution. Another alternative would be to make GetResult async and return the result after all rules are executed, but that is a breaking change and I'd prefer to avoid any breaking changes for this.

Anyway, I'll think about it a bit more and probably come up with some solution.

abgenullt commented 5 years ago

That would be great! I hope you find a good solution.

Thank you for your effort!