Closed PavelVsl closed 4 years ago
I agree with the validation, but is there not a library that picks up the "rules" from my model using data annotations? I don't want to define the requirements on my my model and then again for the validation with rules. Maybe it's me, but I like seeing the validation logic on my model.
public class Customer
{
[StringLength(maximumLength: 50 , MinimumLength = 10, ErrorMessage = "The property {0} should have {1} maximum characters and {2} minimum characters")]
public string Name { get; set; }
}
DataAnnotationValidator does this job. But it'd not as flexible as FluentValidator. And on DataAnotations is some minor problems with localization.
https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-3.1
Main problems of current implementation of forms in Oqtane:
<EditForm Model="@Model" OnValidSubmit="@Save">
<DataAnnotationsValidator/>
<ValidationSummary/>
.... form body ........
<button type="submit" >Save changes</button>
</EditForm>
@sbwalker Why is not used models, validators and ms components in forms? Any reason? fields in component class as model is against all patterns how to make forms in blazor. And terrible possibilities to easy refactoring. I smell old .asp here. I'm renaming same fields again and again .....
string name = "";
List<Tenant> tenants;
string tenant = "";
List<Alias> aliases;
string urls = "";
int logofileid = -1;
FileManager filemanager;
string themetype;
string layouttype;
string containertype;
string smtphost = "";
string smtpport = "";
string smtpssl = "";
string smtpusername = "";
string smtppassword = "";
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
string deletedby;
DateTime? deletedon;
string isdeleted;
Honestly, development of Oqtane began when Blazor was in the early Previews - back in 2018. At that time Blazor concepts like EditForm and many other features did not exist. And the code examples for Blazor were very limited at that time so the goal of the initial razor components was simply to make them functional. And as time went on the goal was to get all the of the required features completed for MVP - rather than going back and refactoring all of the existing functionality which was already working.
Also the built-in EditForm has 'limitations', for example the person has to sometimes hit the submit button twice after correcting validation errors.
Also some built-in Blazor features do not work as expected when they are in the dynamically injected controls that Oqtane implements.
Ok, thank you for explanation. Code is little bit ugly but working. Sorry for my strong statements yesterday. I will focus on clean-up server, help with MVP, and this can be task for future versions, not for now.
Module developers have the freedom to use EditForm, annotations, etc... in their own modules but that does mean these techniques need to be used in the core framework. For V1 the core framework will use the current approach. Closing this issue and can revisit in V.Next.
We have to implement validation. Not necessary for MVP but think about it. simple one DataAnnotationsValidator or something like https://github.com/ryanelian/FluentValidation.Blazor I'm using it and it's easy.