dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.6k stars 25.29k forks source link

[RC1] Add documentation on DisplayName for validation messages #19633

Closed captainsafia closed 4 years ago

captainsafia commented 4 years ago

We now support setting a DisplayName attribute on InputNumber, InputDate, and InputSelect components. So for example, I can have a form that looks like this.

@page "/form"

<EditForm Model="@this" OnValidSubmit="@HandleValidSubmit">
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" id="birth-date">Date of Birth</span>
         </div>
         <InputDate Class="form-control" Id="DateOfBirth" @bind-Value="@BirthDate" DisplayName="birthday"/>
          <div class="invalid-feedback d-block">
              <ValidationMessage For="@(() => BirthDate)" />
          </div>
    </div>
</EditForm>

@code {
    public DateTime BirthDate { get; set; }

    public void HandleValidSubmit()
    {
        Console.WriteLine("foo");
    }
}

If the date field is invalid, then the validation message will read:

The birthday must be a date.

Wheras previously, it would show this.

The BirthDate must be a date.

We probably want to add this under the "Validation Support" heading.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mxmissile commented 3 years ago

Why does this not apply to <InputText...> also?

guardrex commented 3 years ago

Moved to https://github.com/dotnet/AspNetCore.Docs/issues/22515.

@mxmissile ... Best to open a new issue. We don't work closed issues/PRs.