-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 feat(Form): add support for validate single field (#1980)
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
docs/Masa.Blazor.Docs/Examples/components/forms/ValidateField.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@using System.ComponentModel.DataAnnotations | ||
@using Microsoft.AspNetCore.Components.Forms | ||
|
||
<MCard Width="360" Outlined Class="pa-4 mx-auto"> | ||
<MForm @ref="_form" Model="@_model"> | ||
<MTextField @bind-Value="@_model.Email" | ||
Filled | ||
Dense | ||
Placeholder="Email" | ||
PersistentPlaceholder> | ||
</MTextField> | ||
<div class="d-flex align-center"> | ||
<MTextField @bind-Value="@_model.Code" | ||
Filled | ||
Dense | ||
Placeholder="Code" | ||
PersistentPlaceholder | ||
HideDetails="true" | ||
Class="mr-2"> | ||
</MTextField> | ||
<MButton OnClick="@SendCode" Depressed Color="secondary">Send Code</MButton> | ||
</div> | ||
</MForm> | ||
</MCard> | ||
|
||
@code { | ||
|
||
private MForm? _form; | ||
private Model _model = new(); | ||
|
||
class Model | ||
{ | ||
[Required] [EmailAddress] public string? Email { get; set; } | ||
|
||
[Parameter] public string? Code { get; set; } | ||
} | ||
|
||
private void SendCode() | ||
{ | ||
var isEmailValid = _form!.Validate(FieldIdentifier.Create(() => _model.Email)); | ||
if (isEmailValid) | ||
{ | ||
// send code | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters