Hi,
I want to create an AutoComplete component. Unfortunately, I did not find a sample for this on the site.
Thank you
|
<SfAutoComplete TValue="TVal" TItem="TItemss" DataSource="@customData">
<AutoCompleteFieldSettings Text="Text" Value="Text"></AutoCompleteFieldSettings>
</SfAutoComplete>
@code {
[Parameter]
public List<TItemss> customData { get; set; }
[Parameter]
public EventCallback<TVal> DDLValueChanged { get; set; }
} |
|
<AutoComplete TVal="string" TItemss="Games" customData="@LocalData"></AutoComplete>
@code{
public string value { get; set; }
public class Games
{
public string ID { get; set; }
public string Text { get; set; }
}
List<Games> LocalData = new List<Games> {
new Games() { ID= "Game1", Text= "American Football" },
new Games() { ID= "Game2", Text= "Badminton" },
new Games() { ID= "Game3", Text= "Basketball" },
new Games() { ID= "Game4", Text= "Cricket" },
new Games() { ID= "Game5", Text= "Football" },
new Games() { ID= "Game6", Text= "Golf" },
new Games() { ID= "Game7", Text= "Hockey" },
new Games() { ID= "Game8", Text= "Rugby"},
new Games() { ID= "Game9", Text= "Snooker" },
new Games() { ID= "Game10", Text= "Tennis"},
};
} |
Hi Ponmani Murugaiyan,
Thanks for the tips. How can @ bind-value and ValidationMessage be introduced as a component parameter?
Thank you
Hi Ponmani Murugaiyan,
Thank you very much. The bug was fixed. Is it possible to include error text ValidationMessage inside the component?
Thank you
|
|
Hi Ponmani Murugaiyan,
The uploaded source does not appear to be valid. ValidationMessage is not included in the component.
<EditForm Model="@annotation">
<DataAnnotationsValidator />
<div>
<CustomTextbox TVal="string" TItemss="Countries" Country="@Country"
@bind- Value="@annotation.NameCustom">
</CustomTextbox>
<ValidationMessage For="@(() => annotation.NameCustom)" />
</div>
<div class="sfButton">
<SfButton type="submit" IsPrimary="true">Submit</SfButton>
</div>
</EditForm>
Thank you
Hi Ponmani Murugaiyan,
I want to remove the following code from the page and add it to the AutoComplete component.
<ValidationMessage For="@(() => annotation.NameCustom)" />
And if possible as follows
<EditForm Model="@annotation">
<DataAnnotationsValidator />
<div>
<CustomTextbox TVal="string" TItemss="Countries" Country="@Country"
@bind- Value="@annotation.NameCustom"
ShowValidationMessage="true"
ValidationMessageFor="@annotation.NameCustom " >
</CustomTextbox>
</div>
<div class="sfButton">
<SfButton type="submit" IsPrimary="true">Submit</SfButton>
</div>
</EditForm>
Thank you
Hi Ponmani Murugaiyan,
Thank you for your help.
Hi Ponmani Murugaiyan,
In the custom component for AutoComplete, how can I give focus to the custom component for AutoComplete?
thank you
Hi Sarah,
We can add the focus to the component using JSInterop and the ID of the component. We have prepared a sample for the reported query and shared the sample link below for reference.
<SfAutoComplete ID="AutoComplete1" @ref="AutoCompleteObj" Value="@Value" ValueChanged="ValueChanged" @oninput="@InputHandler" ValueExpression="@ValueExpression" TValue="TVal" TItem="TItemss" ShowClearButton="true" Placeholder="e.g. Australia" DataSource="@Country"> <AutoCompleteFieldSettings Text="Name" Value="Name"></AutoCompleteFieldSettings> </SfAutoComplete> |
protected override async Task OnAfterRenderAsync(bool firstRender) { await JSRuntime.InvokeAsync<object>("Focus"); } |
[Script.js] function Focus() { document.getElementById("AutoComplete1").focus(); } |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorAppTest1503940368
Kindly try the above suggestion and let us know if this meets your requirement.
Regards,
Udhaya Kumar D
Hi UdhayaKumar Duraisamy,
Is it possible to send the name of AutoComplete1 as a parameter? This is because the component has different names on different pages.
thank you
Hi Sarah,
You can focus the autocomplete component using ref and created event and FocusAsync method instead of ID property as like mentioned in the below code snippet. Please refer to the sample for more reference.
|
<SfAutoComplete ID="AutoComplete1" @ref="AutoCompleteObj" Value="@Value" ValueChanged="ValueChanged" @oninput="@InputHandler" ValueExpression="@ValueExpression" TValue="TVal" TItem="TItemss" ShowClearButton="true" Placeholder="e.g. Australia" DataSource="@Country"> <AutoCompleteEvents TValue="TVal" TItem="TItemss" Created="OnCreated"></AutoCompleteEvents> <AutoCompleteFieldSettings Text="Name" Value="Name"></AutoCompleteFieldSettings> </SfAutoComplete> |
|
protected async Task OnCreated() { this.AutoCompleteObj.FocusAsync(); } |
Sample
: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorAppTest12116143152
Regards,
Udhaya Kumar D
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi UdhayaKumar Duraisamy,
Thank you very much for the help. There are two cases:
1- Naturally, we can have multi CustomAutoCompleteComponents on one page, so we want to focus on a specific component.
2- We want to give focus to the component at different times (page loading time, after loading and performing certain operations).
Perhaps it is better to consider a parameter for the component, for example Focused, that whenever this parameter becomes True, focus will be given to the component.
Hi Sarah,
Yes, we can get the instances of the custom component using the @ref property wherever necessary. You can refer to the following blog for more details about it.
Regards,
Udhaya Kumar D
Hi UdhayaKumar Duraisamy ,
I rechecked the source below, but the focus is not transferred to the component when the page is loaded.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorAppTest12116143152
Thank you
Hi Sarah,
We have validated the shared sample on our end. The reported issue is not reproduced in the latest NuGet version as per your scenario. So, we suggest you upgrade to the latest version to resolve the reported issue on your end. Please refer to the below sample for more details.
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorAppTest1271487863
Regards,
Udhaya Kumar D