-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forms and validation #5460
Comments
share models with dataannotations between blazor and backend |
do you plan a support like ? |
Aye! Please do this the same way it works today in ASP.NET Core! through Data Annotations, with the same locking system until all the rules informed are validated successfully. Blazor will be magnificent with this functionality |
Don't forget about localization and cultures:
|
How about using FluentValidation? |
Please, try to ship this with 0.5.0! What do you think? |
Intending to do some early design work in 0.6.0 (not actually delivering the feature). |
Not everyone is fond of the current data annotation validation feature since I do believe in the idea of keeping the domain model rather simplistic. Therefore I really suggest to have a validation method that returns a dictionary with the error messages but the method itself can be overwritten. |
Nice to have feature, but I'd see other topics (like full debugger support) with more priority. |
@DNF-SaS Thanks for the feedback! Blazor is actually a composition of two efforts: 1. The Blazor UI framework, and 2. .NET support for WebAssembly (via Mono). Debugging is being handled on the Mono side and the work is tracked in the https://github.com/mono/mono repo. |
I'm also all for open validation, so not tied to DataAnnotation or anything in particular. This is really important. |
I implemented client side form validation with DataAnnotation. It's just a POC but it's working, you can find the details here : https://remibou.github.io/Client-side-validation-with-Blazor-and-Data-Annotations/. Please send feedback, I'll try to create a nuget package from it later. |
Moving this out of 0.6.0. |
Here is some rough mockups based on templated components: https://gist.github.com/SteveSandersonMS/6ac9458e3fc5b49c199777627fff3fc8 There are so many different ways we could structure designs for this. For those wondering why we moved it out of 0.6.0, as commented earlier, our only goal in 0.6.0 was to consider possible designs, which is what we have done. Real implementation will be later. |
@SteveSandersonMS Seems promising, one comment though If we put As for the model centric style of Validations I think it'd be nice if I could somehow also use the Attributes on the shared DTO to validate them also on server-side going by the "Don't trust the client-side too much", it would make validations easier for those who uses .Net full stack. I also like your idea of having a default template for the Model centric one that one could override using a Templated component tag perhaps with it's |
@SteveSandersonMS my 2 cents :
|
I also tried using both a template and through a model but concluded that I would actually prefer using an extension mechanism on existing elements instead. For example extending the input element with a custom attribute that the user can implement to extract model information of their choice Maybe the goals are a bit different. I didn’t take it further because I didn’t see any interests. I will open a separate issue for it to further explain. |
You can find it here https://github.com/aspnet/Blazor/issues/1465 |
I back @RemiBou attribute approach in the sense that it would avoid developing twice the same sort of validations on both client and server. |
Will Blazor validation allow async validation that runs on the server and synchronous validation for checking validity on the server too? And prioritize the sync validations over the async ones? For example, first validate that the email address is a valid email address (sync on the client) then check that it hasn't already been registered on the web site (async on the server). Will it have the ability to show different content for invalid, valid and pending state? E.g.
I think these are two good things about Angular that should be available in Blazor. |
Would it not be wise to build an implementation based on one of the existing rich client UI patterns, such as IDataErrorInfo, or better INotifyDataErrorInfo? It feels like you'd be rather reinventing the wheel if you didn't look at reusing an existing pattern. The only question would be which pattern I suppose! |
I would be uncomfortable with rules having to be defined in the template. In my experience, this leads to a lot of duplication, as you often need to test validity on both sides of an API boundary, or on multiple UIs. |
Taking a look of some peoples point of view, we got to keep this simple, not reinvent the wheels and to keep it simple and DataAnnotation is the way to go. I totally agree @RemiBou on his second bullet point. This would ensure that data will have same validations for both client and server sides. Why we just don't implement something like this that already exists
and then get the errors messages like
and the display the errors messages in a custom component like
Based on UX the best approach would be to apply css colors to the input and display the error message below it as @RemiBou implementations and we need to take also in consideration internationalization stuff for errors messages, input labels, message dialogs, etc. |
There are a couple philosophies on validation rules, and I think it is important to keep them in mind when considering validation features in any UI framework. One philosophy says that validation rules aren't real business rules, and they can (and should) be enforced by the UI, not by an official business layer. And I get that, especially in the js-based web world where the business layer is almost always in .NET/Java on a server, and whatever is running in the browser is (at best) a shadow copy of the real rules. Another philosophy, widely used in the smart client frameworks over the past 20+ years, is that the UI shouldn't embody the rules at all, but rather should provide interfaces or events or something such that the business layer can report to the UI what is good/bad and the UI can decide how to display that information to the user. I'm a strong advocate of the second philosophy, because I'm a strong advocate of separation of concerns and having an official business layer separate from the presentation. To make such separation possible it is necessary to have some abstraction so all the rules (including validation) run in the business layer, but have immediate results displayed to the user. XAML is amazingly good at this via a combination of interfaces ( So my plea is that if you go down the road of building validation do-dads into the UI framework (as I suspect is inevitable), that you also make sure to support the more powerful model of keeping all business logic in a business layer and provide an abstraction layer so the results of rules can be displayed to the user by the presentation layer immediately. After all, what we're talking about here is running the business layer (or parts of it) in the browser directly via wasm - so the direct analogy is to WPF. Having something comparable to the rich data binding and |
No description provided.
The text was updated successfully, but these errors were encountered: