Created event not firing

Here is the relevant code:

                    <SfAutoComplete @ref="GrowerAutoComplete"
                                TValue="GrowerModel"
                                TItem="GrowerModel"
                                Placeholder="Any part of Grower Name"
                                DataSource="@growers"
                                Autofill=true
                                Highlight=true
                                Created="@onCreate"
                                @bind-Value="@Grower">
                        <AutoCompleteFieldSettings Value="NameForCbo" />
                    </SfAutoComplete>
        private async Task onCreate()
        {
            int x; // I placed a breakpoint here and it does not reach this line.
        }


Is this a bug? Or am I doing something wrong. I pulled the code from a forum solution, so it looks like it SHOULD work -- unless maybe the Created event doesn't exist for autocomplete?

My goal is to set focus to this. It's in a form that doesn't render until a variable is set. The form is part of a page.

I tried putting the FocusAsync command in the method that sets the variable that causes the form to render, but the line tries to run before the form has a chance to render. That's why I tried the Created event.



3 Replies

UD UdhayaKumar Duraisamy Syncfusion Team March 8, 2023 06:44 AM UTC

You have to place the Created event on the <AutoCompleteEvents> instead of the <SfAutoComplete> as in below code snippet. Please refer to the documentation for more information.


<SfAutoComplete @ref="GrowerAutoComplete"

                                TValue="GrowerModel"

                                TItem="GrowerModel"

                                Placeholder="Any part of Grower Name"

                                DataSource="@growers"

                                Autofill=true

                                Highlight=true

                                @bind-Value="@Grower">

                        <AutoCompleteFieldSettings Value="NameForCbo" />

<AutoCompleteEvents TItem="GrowerModel" TValue="GrowerModel" Created="@onCreate"></AutoCompleteEvents>

                    </SfAutoComplete>


Documentation: https://blazor.syncfusion.com/documentation/autocomplete/events#created



KA Keith A Price March 8, 2023 04:44 PM UTC

Yep. That was the key part I missed. Thanks!



UD UdhayaKumar Duraisamy Syncfusion Team March 9, 2023 04:08 AM UTC

We are happy to assist you. Please get back to us if you need any further assistance on this.


Loader.
Up arrow icon