Hi,
I have added a multiselect dropdown with Mode="@VisualMode.Box" and I am trying to add a textbox in the header template so I can do the filtering on it without using the default filtering on the box itself. But it won't allow me to type on it because the focus is fixated on the multiselect selected items box. How can I focus on the custom textbox instead?
Thank you.
|
@inject IJSRuntime JS
<SfMultiSelect TValue="string[]" TItem="Countries" Placeholder="e.g. Australia" DataSource="@Country">
<MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>
<MultiSelectEvents TValue="string[]" TItem="Countries" Opened="OpenEvent" OnClose="PopupClose"></MultiSelectEvents>
<MultiSelectTemplates TItem="Countries">
<HeaderTemplate>
<div>
<input id="customInput" @onfocusin="CuastomInputFocus"/>
@*<InputText id="customInput" @onfocusin="@CuastomInputFocus" @bind-Value="TextIbnput"></InputText> *@
</div>
</HeaderTemplate>
</MultiSelectTemplates>
</SfMultiSelect>
@code {
public string TextIbnput { get;set; }
public Boolean isFocus { get; set; } = false;
void CuastomInputFocus()
{
isFocus = true;
}
void PopupClose(PopupEventArgs args)
{
if (isFocus)
{
args.Cancel = true;
isFocus = false;
} else
{
args.Cancel = false;
}
}
protected async Task OpenEvent(Syncfusion.Blazor.DropDowns.PopupEventArgs args)
{
await JS.InvokeAsync<string>("Focus", "customInput");
}
public class Countries
{
public string Name { get; set; }
public string Code { get; set; }
}
List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = "AU" },
new Countries() { Name = "Bermuda", Code = "BM" },
new Countries() { Name = "Canada", Code = "CA" },
new Countries() { Name = "Cameroon", Code = "CM" },
new Countries() { Name = "Denmark", Code = "DK" }
};
} |
|
function Focus(id) {
setTimeout(() => {
document.getElementById("customInput").focus();
}, 500);
} |
Hi Suresh,
Thank you for your example. This is exactly what I was after. However, when I have implemented your solution in my project the pop up exists on the first click on the multiselect box. I need to click twice to start typing on the filter textbox. Also, when I need to close the popup I need to click twice outside of the control as well. I have made a small capture (click) so it will explain better. What do you think causing this? I need to mention this issue does not happen in your example. Only in my project.
Than
Hi Suresh,
All good mate, I have figured it out. Thanks a lot for your help. Cheers!