Forms with SSR
All inputs support model-binding, even when using <EditForm> in the static rendering mode. These examples use simple binding with a local variable for simplicity purposes.
Text
<CleanInputText @bind-Value="@(text)" placeholder="Hello world!" />
<CleanInputText @bind-Value="@(username)" PrefixContent="@(Icons.User)" SuffixContent="@(Icons.Id)" />
@code {
private string? text;
private string? username = "admin";
}
Number
<CleanInputNumber @bind-Value="@(value)" />
<CleanInputNumber @bind-Value="@(value)" PrefixContent="@(Icons.CoinEuro)" SuffixContent="@(Icons.CoinBitcoin)" />
@code {
private int value;
}
Check
<CleanInputCheckbox @bind-Value="@(value)" />
<CleanInputCheckbox @bind-Value="@(value)">
Stay signed in?
</CleanInputCheckbox
@code {
private bool value;
}
Switch
<CleanInputSwitch @bind-Value="@(value)" />
<CleanInputSwitch @bind-Value="@(value)">
Enabled
</CleanInputSwitch>
@code {
private bool value;
}
Date
Important
Make sure to add the proper value to the
Typeparameter.
The <CleanInputDate /> component supports binding with System.DateOnly, System.DateTime, System.DateTimeOffset and System.TimeOnly variables/properties.
@using Microsoft.AspNetCore.Components.Forms
<CleanInputDate @bind-Value="@(date)" PrefixContent="@(Icons.Calendar)" />
<CleanInputDate @bind-Value="@(dateTime)"
Type="@(InputDateType.DateTimeLocal)"
PrefixContent="@(Icons.CalendarClock)"
SuffixContent="@(Icons.CalendarCheck)" />
<CleanInputDate @bind-Value="@(time)"
Type="@(InputDateType.Time)"
PrefixContent="@(Icons.Clock)"
SuffixContent="@(Icons.Alarm)" />
@code {
private DateOnly? date;
private DateTimeOffset dateTime = DateTimeOffset.UtcNow;
private TimeOnly? time;
}
TextArea
<CleanInputTextArea @bind-Value="@(text)" placeholder="Hello world!" ContainerClass="flex-1" />
<CleanInputTextArea @bind-Value="@(description)" rows="4" ContainerClass="flex-1" />
@code {
private string? text;
private string description = """
A modern, clean and elegant UI library for Blazor/Razor.
Its goal is to make the developers life easier and way less troublesome, while providing users with a clean and usable UI.
""";
}
File
File uploads work in a specific, possibly unintuitive, way. They can also be an easy-to-exploit security issue. Make sure to read this documentation page to make sure you're handling files correctly.
Note: the displayed method of rendering the uploaded files in the demo only works in the Interactive rendering mode. However, the input component itself works as expected in the Static rendering mode.
@using Microsoft.AspNetCore.Components.Forms
<CleanInputFile OnChange="@(UpdateFiles)" multiple />
@if (files is { Count : > 0 })
{
<ul>
@foreach (var file in files)
{
<li @key="@($"file-{file.Name}")">
@(file.Name) (@(file.Size.ToString())b)
</li>
}
</ul>
}
@code {
private IReadOnlyList<IBrowserFile>? files;
private void UpdateFiles(InputFileChangeEventArgs args) =>
files = args.GetMultipleFiles(5);
}
Radio
<CleanInputRadioGroup @bind-Value="@(@checked)" style="margin-inline-end: var(--spacing-xs)">
<CleanInputRadio Value="@(true)">
Yes
</CleanInputRadio>
<CleanInputRadio Value="@(false)">
No
</CleanInputRadio>
</CleanInputRadioGroup>
<CleanInputRadioGroup @bind-Value="@(value)" Vertical>
<CleanInputRadio Value="@("Hello")">
Hello
</CleanInputRadio>
<CleanInputRadio Value="@("there")">
there
</CleanInputRadio>
<CleanInputRadio Value="@("general")">
general
</CleanInputRadio>
<CleanInputRadio Value="@("Kenobi")">
Kenobi
</CleanInputRadio>
</CleanInputRadioGroup>
@code {
private bool @checked;
private string? value;
}
Range
<CleanInputNumber @bind-Value="@(value)" type="range" min="0" max="100" />
<CleanInputNumber @bind-Value="@(value2)"
PrefixContent="@(Icons.Minus)"
SuffixContent="@(Icons.Plus)"
type="range"
min="0"
max="100" />
@code {
private int value = 50;
private int value2;
}