-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Form): optimize default behavior, add demos and update docs (#2084)
* (Form): optimize default behavior, add demos and update docs * update
- Loading branch information
Showing
14 changed files
with
248 additions
and
123 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
docs/Masa.Blazor.Docs/Examples/components/forms/AutoLabel.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,45 @@ | ||
@using System.ComponentModel.DataAnnotations | ||
@using System.ComponentModel | ||
|
||
<MForm Model="_model" | ||
AutoLabel | ||
Class="mx-auto" | ||
Style="width: 360px"> | ||
<MTextField @bind-Value="_model.Name" Filled> | ||
</MTextField> | ||
<MSelect @bind-Value="_model.Item" | ||
Items="@_sports" | ||
Filled | ||
ItemText="u => u" | ||
ItemValue="u => u"> | ||
</MSelect> | ||
<MButton Type="submit" Block Color="primary">Submit</MButton> | ||
|
||
@* <Masa.Blazor.Components.Form.AutoLabelOptions AttributeType="@typeof(DisplayAttribute)"/> *@ | ||
</MForm> | ||
|
||
@code { | ||
|
||
class Model | ||
{ | ||
[Display(Name = "Username")] | ||
[Required] | ||
[MaxLength(10, ErrorMessage = "Name must be less than 10 characters")] | ||
public string Name { get; set; } | ||
|
||
[Display(Name = "Favorite sport")] | ||
[Required] public string Item { get; set; } | ||
} | ||
|
||
private bool _valid = true; | ||
private Model _model = new(); | ||
|
||
List<string> _sports = new() | ||
{ | ||
"Basketball", | ||
"Football", | ||
"Tennis", | ||
"Swimming" | ||
}; | ||
|
||
} |
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
65 changes: 0 additions & 65 deletions
65
docs/Masa.Blazor.Docs/Examples/components/forms/ValidateComplexType.razor
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
docs/Masa.Blazor.Docs/Examples/components/forms/ValidateOnDemo.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,59 @@ | ||
@using System.ComponentModel.DataAnnotations | ||
@using System.ComponentModel | ||
|
||
<div style="width: 360px;" class="mx-auto"> | ||
<MRadioGroup @bind-Value="@_validateOn" HideDetails="true" Label="Validate On"> | ||
<MRadio Value="ValidateOn.Input" Label="On input"></MRadio> | ||
<MRadio Value="ValidateOn.Blur" Label="On blur"></MRadio> | ||
<MRadio Value="ValidateOn.Submit" Label="On submit"></MRadio> | ||
</MRadioGroup> | ||
|
||
<MDivider Class="my-2" /> | ||
|
||
<MForm Model="_model" | ||
ValidateOn="_validateOn" | ||
AutoLabel> | ||
<MTextField @bind-Value="_model.Name" Filled | ||
Hint="Least 5 characters" | ||
PersistentHint> | ||
</MTextField> | ||
<MSelect @bind-Value="_model.Item" | ||
Items="@_sports" | ||
Filled | ||
ItemText="u => u" | ||
ItemValue="u => u"> | ||
</MSelect> | ||
<MSlider @bind-Value="_model.Age" ThumbLabel="@("always")"></MSlider> | ||
<MButton Type="submit" Block Color="primary">Submit</MButton> | ||
</MForm> | ||
</div> | ||
@code { | ||
|
||
class Model | ||
{ | ||
[Display(Name = "Username")] | ||
[Required] | ||
[MinLength(5)] | ||
public string Name { get; set; } | ||
|
||
[Display(Name = "Favorite sport")] | ||
[Required] public string Item { get; set; } | ||
|
||
[Display(Name = "Age")] | ||
[Range(18, 60)] | ||
public int Age { get; set; } | ||
} | ||
|
||
private bool _valid = true; | ||
private Model _model = new(); | ||
private ValidateOn _validateOn; | ||
|
||
List<string> _sports = new() | ||
{ | ||
"Basketball", | ||
"Football", | ||
"Tennis", | ||
"Swimming" | ||
}; | ||
|
||
} |
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
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
Oops, something went wrong.