AutoCompleteView - ShowSuggestions used from Focused and TextChanged events is misbehaving

1 Answer 20 Views
AutoCompleteView
Flotman
Top achievements
Rank 1
Flotman asked on 05 Jan 2024, 03:09 PM

Hi,

I need to show suggestios when user focues on control or deletes text completely but this is not working as expected. My custom filter function already retruns data properly for empty search strings.

This is my TextCahnged event implemtation:

        private void usersAutoCompleteView_TextChanged(object sender, TextChangedEventArgs e)
        {
            var control = (RadAutoCompleteView)sender;
            if (string.IsNullOrEmpty(e.NewTextValue) && !string.IsNullOrEmpty(e.OldTextValue))
            {
                control.ShowSuggestions();
            }
        }

And this is my Focused event implementation:

        private void usersAutoCompleteView_Focused(object sender, FocusEventArgs e)
        {
            var control = (RadAutoCompleteView)sender;
            if (string.IsNullOrEmpty(control.SearchText))
            {
                control.ShowSuggestions();
            }
        }

I am also using SuggestionItemSelected event but is really simple: 
      private void usersAutoCompleteView_SuggestionItemSelected(object sender, Telerik.XamarinForms.Input.AutoComplete.SuggestionItemSelectedEventArgs e)
      {
          MyUser = (e.DataItem as MyModel).User;
      }

If I use Focused for showing Suggestions everything works fine, but when I added TextChanged nothings works as shoud:

1) Suggestion menu is never shown from TextChanged event

2) When I select Item from Suggsetion menu, text on the control gets immediately deleted (Text changed is getting called again with empty NewTextValue)

3) When I remove usage for TextChanged  event misbehaviour is still there. I need to clean whole build/restart VS/emulator to get it running again.

 

How should I achieve this functionality? It should be simple, for me it's looks like a common scenario

 

 

 

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 08 Jan 2024, 04:46 PM

Hi,

1) Show SuggestionView on TextChanged: In order to achieve the scenario you need to add a dispatcher inside the TextChanged event handler:

private void autoCompleteView_TextChanged(object sender, TextChangedEventArgs e)
{
    var control = (RadAutoCompleteView)sender;
    if (string.IsNullOrEmpty(e.NewTextValue) && !string.IsNullOrEmpty(e.OldTextValue))
    {
        Device.StartTimer(TimeSpan.FromMilliseconds(500), () => 
        { 
            control.ShowSuggestions();
            return false;
        });
                
    }
}

2) and 3) When selecting an item, text gets deleted. I cannot reproduce such behavior. I have attached the xaml and cs files I used. I would like to ask you to send me the exact setup you have and a video of the behavior. You can open a support ticket and attach the files there, if you do not want to add them to the forum.

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Flotman
Top achievements
Rank 1
commented on 08 Jan 2024, 10:32 PM

Thanks, the trick with Timer worked. As for points 2) and 3) probably I have bug somewhere else and fixed it, because problem is not occurring anymore.
Tags
AutoCompleteView
Asked by
Flotman
Top achievements
Rank 1
Answers by
Didi
Telerik team
Share this question
or