dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Validation summary to show validation errors from all forms #22221

Closed carlblanchard closed 2 years ago

carlblanchard commented 4 years ago

As per the comments in issue https://github.com/dotnet/AspNetCore.Docs/issues/18481#issuecomment-633968572

It would be nice if the ValidationSummary control in Blazor client could show errors across all forms on the page.

<section class="section">
            <EditForm> throws error due to no Model (Unhandled exception rendering component: EditForm requires a Model parameter, or an EditContext parameter, but not both)
                <ValidationSummary />
            </EditForm>
            <div class="row">
.... more HTML

 <EditForm Model="@UserPreferences" OnValidSubmit="LanguageSettingOnValidSubmit">
.... more form contents
</EditForm>

.... more HTML
<EditForm Model="@UserPreferences" OnValidSubmit="TimezoneOnValidSubmit">
.... more form contents
</EditForm>
mkArtakMSFT commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

mrpmorris commented 4 years ago

If you have 3 classes you want to work on (for example) then follow these steps

  1. Create a view model class that has a property for each

    public class MyViewModel
    {
    public Person Applicant { get; set; }
    public CourseInfo CourseInfo { get; set; }
    public BankDetails BankDetails { get; set; }
    }
  2. Create an instance of MyViewModel in your page component

  3. Create an instance of EditContext in your page component, passing in the object from 2

  4. In every one of your <EditForm> components you can pass an explicit EditContext like so

<EditForm EditContext=MyEditContext>
  <DataAnnotationsValidator/>
  <InputForm @bind-Value=MyViewModel.Application.FamilyName/>
</EditForm>

<EditForm EditContext=MyEditContext>
  <DataAnnotationsValidator/>
  <InputForm @bind-Value=MyViewModel.BankDetails.AccountHolderName/>
</EditForm>

You can show a single list of errors like this

<EditForm EditContext=MyEditContext>
  <ValidationSummary/>
</EditForm>
mkArtakMSFT commented 2 years ago

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.