Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/Demo/Shared/Pages/BasicFormBuiltInComponents.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@page "/basicform-built-in-components"
@using Microsoft.Extensions.Logging
@inject ILogger<BasicFormBuiltInComponents> Logger

<h1>Starfleet Starship Database</h1>

<h2>New Ship Entry Form</h2>

<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<FluentValidationSummary />

<p>
<label>
Expand Down Expand Up @@ -66,7 +64,7 @@

private void HandleValidSubmit()
{
Logger.LogInformation("HandleValidSubmit called");
DemoLogger.WriteLine("HandleValidSubmit called");

// Process the valid form
}
Expand Down
15 changes: 6 additions & 9 deletions examples/Demo/Shared/Pages/BasicFormFluentUIComponents.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@page "/basicform-fluentui-components"
@using Microsoft.Extensions.Logging
@inject ILogger<BasicFormFluentUIComponents> Logger

<h1>Starfleet Starship Database</h1>

<h2>New Ship Entry Form</h2>

<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<FluentValidationSummary />

<div style="display:grid; gap: 5px;">
<div><FluentTextField @bind-Value="starship.Identifier">Identifier:</FluentTextField></div>
Expand All @@ -24,27 +22,26 @@
<div><FluentNumberField @bind-Value="starship.MaximumAccommodation"> Maximum Accommodation:</FluentNumberField></div>
<div><FluentCheckbox @bind-Value="starship.IsValidatedDesign">Engineering Approval</FluentCheckbox></div>
<div><label>Production Date:</label>
<FluentCalendar @bind-SelectedDates="prodDate" />
<FluentDatePicker @bind-Value="prodDate" />
</div>
<div><FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Submit</FluentButton></div>
<div><a href="http://www.startrek.com/">Star Trek</a>, ©1966-2019 CBS Studios, Inc. and <a href="https://www.paramount.com">Paramount Pictures</a></div>
<div><a href="http://www.startrek.com/">Star Trek</a>, ©1966-2023 CBS Studios, Inc. and <a href="https://www.paramount.com">Paramount Pictures</a></div>
</div>
</EditForm>

@code {
List<DateOnly> prodDate = new();
DateTime? prodDate = DateTime.Now;

protected override void OnInitialized()
{
prodDate.Add(new DateOnly(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
starship.ProductionDate = prodDate[0];
starship.ProductionDate = new DateOnly(prodDate!.Value.Year, prodDate!.Value.Month, prodDate!.Value.Day);
}

private Starship starship = new();

private void HandleValidSubmit()
{
Logger.LogInformation("HandleValidSubmit called");
DemoLogger.WriteLine("HandleValidSubmit called");

// Process the valid form
}
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Components/Forms/FluentValidationSummary.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@namespace Microsoft.Fast.Components.FluentUI
@using Microsoft.AspNetCore.Components.Forms
@inherits ValidationSummary

@{ var validationMessages = Model is null ? FluentEditContext.GetValidationMessages() : FluentEditContext.GetValidationMessages(new FieldIdentifier(Model, string.Empty));

@if (validationMessages.Count() > 0)
{
<div @attributes="AdditionalAttributes">
<ul class="validation-errors">

@foreach (var error in validationMessages)
{
<li class="validation-mesage">@error</li>
}
</ul>
</div>
}
}


10 changes: 10 additions & 0 deletions src/Core/Components/Forms/FluentValidationSummary.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;

namespace Microsoft.Fast.Components.FluentUI;

public partial class FluentValidationSummary
{
[CascadingParameter]
public EditContext FluentEditContext { get; set; } = default!;
}
8 changes: 8 additions & 0 deletions src/Core/wwwroot/css/reboot.css
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ textarea {
border: 1px solid black;
}

.invalid::part(root) {
outline: 1px solid var(--error);
}

.invalid[role='checkbox']::part(control) {
outline: 1px solid var(--error);
}

button,
select {
text-transform: none;
Expand Down