-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathBasicFormFluentUIComponents.razor
99 lines (85 loc) · 4.38 KB
/
BasicFormFluentUIComponents.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@page "/basicform-fluentui-components"
@inject DataSource Data
<PageTitle>@App.PageTitle("Basic Form FluentUI")</PageTitle>
<h1>Starfleet Starship Database</h1>
<p>
This form uses the Fluent UI input components. It uses a <code>DataAnnotationsValidator</code>, a <code>FluentValidationSummary</code>
and <code>FluentValidationMessage</code>s.
</p>
<h2>New Ship Entry Form</h2>
<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit" FormName="starship_fluent_entry" novalidate>
<DataAnnotationsValidator />
<FluentValidationSummary />
<FluentStack Orientation="Orientation.Vertical">
<div>
<FluentTextField Name="identifier" @bind-Value="starship.Identifier" Label="Identifier" Required />
<FluentValidationMessage For="@(() => starship.Identifier)" />
</div>
<div>
<FluentTextArea Name="description" Rows=5 Cols=60 @bind-Value="starship.Description" Label="Description (optional)" Required />
<FluentValidationMessage For="@(() => starship.Description)" />
</div>
<div>
<FluentAutocomplete TOption="Country"
Name="countries"
AutoComplete="off"
Required
Label="Select countries"
Width="250px"
Placeholder="Select countries"
OnOptionsSearch="@OnSearchAsync"
MaximumSelectedOptions="3"
OptionText="@(item => item.Name)"
Multiple="true"
@bind-SelectedOptions="@starship.Countries" />
<FluentValidationMessage For="@(() => starship.Countries)" />
</div>
<div>
<FluentSelect Name="class" Id="classification" @bind-Value="starship.Classification" TOption="string" Required Label="Primary Classification">
<FluentOption Value="">Select classification ...</FluentOption>
<FluentOption Value="Exploration">Exploration</FluentOption>
<FluentOption Value="Diplomacy">Diplomacy</FluentOption>
<FluentOption Value="Defense">Defense</FluentOption>
</FluentSelect>
<FluentValidationMessage For="@(() => starship.Classification)" />
</div>
<div>
<FluentNumberField Name="accomodation" @bind-Value="starship.MaximumAccommodation" Label="Maximum Accommodation" Required />
<FluentValidationMessage For="@(() => starship.MaximumAccommodation)" />
</div>
<div>
<FluentCheckbox Name="approved" @bind-Value="starship.IsValidatedDesign" Required Label="Engineering approval" />
<FluentValidationMessage For="@(() => starship.IsValidatedDesign)" />
</div>
<div>
<FluentDatePicker Name="production_date" Id="proddate" @bind-Value="starship.ProductionDate" Label="Production Date" Required />
<FluentValidationMessage For="@(() => starship.ProductionDate)" />
</div>
<div>
<FluentSwitch Name="teleporter" @bind-value="starship.HasTeleporter" Label="Teleporter" CheckedMessage="Fully operational" UncheckedMessage="Under maintenance"/>
<FluentValidationMessage For="@(() => starship.HasTeleporter)" />
</div>
<FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent">Submit</FluentButton>
</FluentStack>
</EditForm>
<div style="margin-top: 3rem;"><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>
@code {
protected override void OnInitialized()
{
starship.ProductionDate = DateTime.Now;
}
IEnumerable<Country> SelectedItems = Array.Empty<Country>();
private async Task OnSearchAsync(OptionsSearchEventArgs<Country> e)
{
var allCountries = await Data.GetCountriesAsync();
e.Items = allCountries.Where(i => i.Name.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase))
.OrderBy(i => i.Name);
}
[SupplyParameterFromForm]
private Starship starship { get; set; } = new();
private void HandleValidSubmit()
{
DemoLogger.WriteLine("HandleValidSubmit called");
// Process the valid form
}
}