-
Notifications
You must be signed in to change notification settings - Fork 10.3k
CompareAttribute ignored with OnValidSubmit EditForm #10643
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
Comments
To get around this, i used the following code using OnSubmit and EditContext |
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project that illustrates the problem. |
If, however, you believe this was an issue on your end, please close the issue. Thanks! |
@mkArtakMSFT |
Thanks @smartprogrammer93. |
@mkArtakMSFT Can you please remove the question Label so the issue will be considered later for Backlog |
I found that this occurs when the EditContextDataAnnotationsExtensions.ValidateModel method does not add the field to the "messages" collection. The method does not include this because ValidationResult has no items in the "MemberNames" array when the Compare attribute is used. See code with comment:
To work around this problem, I suggest changing the implementation of the CompareAttribute.IsValid method to include the validated property name in the method return. Original version
Suggested version:
|
I'm running into the same issue. I was trying to use the compare validator to make an experience similar to GitHub's delete where the user must type a matching name to confirm deletion.
|
My bad i pressed the close button by mistake |
As noted in #10643 (comment), on a form submit Blazor's In 3.1, we're doing a couple of things to address this:
<EditForm Model="myModel" OnValidSubmit="OnSubmit">
<DataAnnotationsValidator />
<InputText Name="Password" /> <ValidationMessage For=@(() => myModel.Password)" />
<InputText Name="ConfirmPassword" /> <ValidationMessage For=@(() => myModel.ConfirmPassword)" />
<ValidationSummary Model="myModel" />
<button class="btn btn-danger" type="submit">Submit</button>
</EditForm> The
This package is marked experimental since our plan is to roll these changes in to CoreFx as part of the 5.0 milestone. Hope this helps. |
* Validation fixes for Blazor * Ensure validation result that are not associated with a member are recorded. Fixes dotnet/aspnetcore#10643 * Add support for showing model-specific errors to ValidationSummary * Add support for nested validation and a more suitable CompareAttribute. Fixes dotnet/aspnetcore#10526
Using an EditForm in Blazor client side
I have a model with compare attribute.
The error message does show when the password and confirm password are not the same but does not prevent form submission for some reason. Once the form is submitted the error message is removed.
Expected behavior
Prevent form submission and keep the error message
The text was updated successfully, but these errors were encountered: