Hi,
I have tried to create a radzen textbox with multi chips so that users can type string and when they press enter or tab it makes it chip and allow them to continue enter more strings. Can you please advise how can I modify below to make it work ?
<RadzenFormField
Text="ShortName"
Style="flex-grow: 1!important;">
<div style="display: block; display: flex; align-items: center;">
<div style="display: flex; flex-wrap: nowrap;">
@foreach (var chip in val)
{
<div class="chip" @key="chip" @onclick="() => VariationValueRemovedHandler(chip)"
style="
height: 25px;
cursor: pointer;
margin: 4px; padding:
8px; background-color:
#e0e0e0; border-radius: 4px;
display: flex;
align-items: center;">
@chip
</div>
}
</div>
<RadzenTextBox id="Variation_Value_Input" @bind-Value="@VariationValue" @onkeydown="(args) => VariationValuesChangeHandler(args)" />
</div>
</RadzenFormField>
@code {
private string? VariationValue;
List<string> val = new List<string>();
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
private async void VariationValuesChangeHandler(KeyboardEventArgs keypress)
{
if (keypress.Key != "Enter" && keypress.Key != "Tab") return;
else
{
val.Add(VariationValue);
}
VariationValue = null;
StateHasChanged();
}
private async void VariationValueRemovedHandler(string strChip)
{
val.Remove(strChip);
}
}
Below is what I want to acheive