Extended control to set the Required attribute
The control now allow the required attribute to be set. This will now give better UX feedback.
This commit is contained in:
parent
4d63c6266c
commit
02e2aeb6d1
|
@ -2,7 +2,7 @@
|
||||||
@inherits LocalizableComponent
|
@inherits LocalizableComponent
|
||||||
|
|
||||||
<div class="app-autocomplete">
|
<div class="app-autocomplete">
|
||||||
<input class="form-control" value="@Value" @oninput="OnInput" @onkeyup="OnKeyUp" placeholder="@Placeholder" autocomplete="off" />
|
<input class="form-control" value="@Value" @oninput="OnInput" @onkeyup="OnKeyUp" placeholder="@Placeholder" autocomplete="off" @attributes="InputAttributes" />
|
||||||
@if (_results != null)
|
@if (_results != null)
|
||||||
{
|
{
|
||||||
<select class="form-select" style="position: relative;" value="@Value" size="@Rows" @onkeyup="OnKeyUp" @onchange="(e => OnChange(e))">
|
<select class="form-select" style="position: relative;" value="@Value" size="@Rows" @onkeyup="OnKeyUp" @onchange="(e => OnChange(e))">
|
||||||
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
Dictionary<string, string> _results;
|
Dictionary<string, string> _results;
|
||||||
|
Dictionary<string, object> InputAttributes { get; set; } = new();
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<string, Task<Dictionary<string, string>>> OnSearch { get; set; } // required - an async delegate method which accepts a filter string parameter and returns a dictionary
|
public Func<string, Task<Dictionary<string, string>>> OnSearch { get; set; } // required - an async delegate method which accepts a filter string parameter and returns a dictionary
|
||||||
|
@ -49,6 +50,19 @@
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string Key { get; set; } // key of item selected
|
public string Key { get; set; } // key of item selected
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool Required { get; set; } // optional - if the item is required
|
||||||
|
|
||||||
|
protected override void OnParametersSet()
|
||||||
|
{
|
||||||
|
if (Required)
|
||||||
|
{
|
||||||
|
if (!InputAttributes.ContainsKey(nameof(Required)))
|
||||||
|
{
|
||||||
|
InputAttributes.Add(nameof(Required), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private async Task OnInput(ChangeEventArgs e)
|
private async Task OnInput(ChangeEventArgs e)
|
||||||
{
|
{
|
||||||
Value = e.Value?.ToString();
|
Value = e.Value?.ToString();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user