MvvmValidation icon indicating copy to clipboard operation
MvvmValidation copied to clipboard

Inconsistent state while async validation

Open abgenullt opened this issue 5 years ago • 2 comments

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

abgenullt avatar Apr 03 '19 12:04 abgenullt

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.

pglazkov avatar Apr 09 '19 15:04 pglazkov

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

Thank you for your effort!

abgenullt avatar Apr 10 '19 06:04 abgenullt