On a popup (ModalDialog) I’m currently working, we use Context.AddRawModelError() to do some server-side custom validations.
I trigger one of those errors, a message is shown in red on the page.
I close and reopen the popup (the VM of the popup is reinstantiated) but the error is still there.
I know about clearing errors on the client-side (https://www.dotvvm.com/docs/4.0/pages/concepts/validation/extensibility)
but how do I clear them up in the server-side code? Context.ModelState.Errors shows me 0 errors while the error message still shows in the page.
I could not find anything of help in the members of Context or among its extension methods. Looking a bit deeper at AddRawModelError() and in the framework’s code, following ModelState.ErrorsInternal, I did not find any means of removing errors from the state by the framework consumer.
So, am I stuck with the client-side clearing of the errors?
This is quite strange, as client-side error should be cleared on each command invocation (if validation is enabled). How exactly are you calling the server? It is also theoretically possible that the error are added back to ModelState after you clear them - Init/Load methods execute before the server-side validation is run.
For the particular DotVVM page in question where we have this issue, the Context.AddRawModelError() is called only inside our DoServerValidationBeforeAnyOperationPersistence() method. This one is called in two places:
in public async Task PreSaveOperationAsync() which is top level method, only used in binding here:
Yes, disabled validation means that Dotvvm won’t clear the client-side error collection on postback. I think you should be able to set Validation.Target to {value: null} to disable automatic validation and only keep the manual one