dotnet / Scaffolding

Code generators to speed up development.
MIT License
633 stars 226 forks source link

Blazor and Razor Pages CRUD scaffolding should visually indicate which fields are required #2899

Open MackinnonBuck opened 1 month ago

MackinnonBuck commented 1 month ago

Overview

Currently, when a form gets generated from a model class, there is no visual indication of which form fields are required. The user must first submit the form before getting feedback about which form fields are required.

Proposed fixes

For each form input that gets generated from a model property annotated with a RequiredAttribute, include additional markup to indicate that the field is required. For example:

<div class="mb-3">
+   <span class="text-danger">*</span>
    <label for="title" class="form-label">Title:</label>
    <InputText id="title" @bind-Value="Movie.Title" class="form-control" aria-required="true" />
    <ValidationMessage For="() => Movie.Title" class="text-danger" />
</div>

Before

image

After

image

MackinnonBuck commented 1 month ago

Related: https://github.com/dotnet/aspnetcore/issues/56312