We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using SfAutoComplete for search history, hiding suggestion box does not work as expected

Thread ID:

Created:

Updated:

Platform:

Replies:

146093 Jul 19,2019 09:06 AM UTC Jan 31,2020 12:27 PM UTC Xamarin.Forms 13
loading
Tags: SfAutoComplete
nvrsttl
Asked On July 19, 2019 09:06 AM UTC

Hi,

I'm using the SfAutoComplete 17.2.0.35 control to provide a search history to the user (Xamarin Forms 4.1.0.581479) .

Each search query is added on top of a string list, which is the datasource of SfAutoComplete.
I want to display the suggestion box with the previous searches only when the text of SfAutoComplete is empty. I have set ShowSuggestionsONFocus and when the user taps into the empty SfAutoComplete the suggestions are displayed.
When the user types the suggestionbox should hide. I have set ValueChanged="SearchBar_OnValueChanged" and in SearchBar_OnValueChanged I set the SuggestionBoxPlacement to None if the user has entered text and to Bottom if the box is empty:

 private void SearchBar_OnValueChanged(object sender, ValueChangedEventArgs e)
        {
            if (searchBar.Text != "") searchBar.SuggestionBoxPlacement = SuggestionBoxPlacement.None;
            else searchBar.SuggestionBoxPlacement = SuggestionBoxPlacement.Bottom; 

Unfortunately while typing the SuggestionBox is not removed, I have to tap into the control again to hide it.
Same if text is entered and then removed, the SuggestionBox only shows again when I tap again into the control.

How can I hide/show the suggestion box based on the entered Text?

Best regards,

Thomas

Muneesh Kumar G [Syncfusion]
Replied On July 24, 2019 01:45 PM UTC

Hi Thomas, 
 
Greetings from Syncfusion. 
 
We have achieved your requirement by using CustomRenderer in Android. We have set the IsDropDown API to false when user starts to enter the text. Please have the sample from the below link, 
 
 
Code Snippet: 
void Handle_ValueChanged(object sender, Syncfusion.SfAutoComplete.XForms.ValueChangedEventArgs e)
        {
            if (autoComplete.Text != "")
            {
                autoComplete.SuggestionBoxPlacement = SuggestionBoxPlacement.None;
            }
            else
            {
                autoComplete.SuggestionBoxPlacement = SuggestionBoxPlacement.Bottom;
            }
        } 
 
Please check with the sample and let us know if you have any concern. 
 
Regards,
Muneesh Kumar G.  
 
 


nvrsttl
Replied On July 31, 2019 07:52 AM UTC

Hi Muneesh ,

thank you for the sample, and sorry for the late reply.

I checked your sample and it works as expected. Then I tried to implement the custom renderer in my solution, but unfortunately it does not work.
It throws an Java.Lang.NullPointerException while calling base.OnElementChanged(e) in OnElementChanged.

I tripplechecked my implementation but can't find any difference.

I Implemented the CustomRenderer class in the Android Project and the CustomClass in the shared project. Only with different class names. I changed SfAutoComplete to my CustomClass in XAML.

Any ideas what this could be? I even tested your project with the same nuget versions of Xamarin/Sf (newest) as I have.

Best regards,

Thomas

Muneesh Kumar G [Syncfusion]
Replied On August 1, 2019 12:34 PM UTC

Hi Thomas, 
 
We have checked the reported issue from our side, and we are afraid we could not reproduce the same. Please have the video for your reference. 
 
 
Please check with the video and if the issue still persists please modify our previous update sample with the issue reproducing and also provide the video representation of the issue which will be helpful for us to analyze further and provide an appropriate solution. 
 
Thanks,   
Muneesh Kumar G.   
 


nvrsttl
Replied On August 16, 2019 10:14 AM UTC

Hi Muneesh,

sorry for the late reply. I checked your video, and yes thats exactly the functionality I need. I can reproduce it with your sample, it works in my emulator as well. Unfortunately I can't find any difference to my code, I tried several things to reproduce the problem in your sample but without luck. Your sample works, I get a Java.Lang.NullPointerException while opening the page. If I click Continue seven times, the page is displayed, but the auto hiding does not work

I copied your View, CustomClass and CustomRendererAndroid to my project, if I hopen the very same view in my project I get the exception. I compared my project settings but I'm unable to find any difference :-/

Do you have any ideas what I can do further debug the problem?

Best regards,

Thomas

Muneesh Kumar G [Syncfusion]
Replied On August 19, 2019 11:07 AM UTC

Hi Thomas,  
 
We are also checked the possible null reference in our base OnElementChanged method. But we can’t find the root cause for this problem. Better you, please share your application with us, this would be helpful for us to find the root cause for this problem.  
  
Thanks,   
Muneesh Kumar G.  
 


nvrsttl
Replied On August 19, 2019 03:46 PM UTC

Hi Muneesh, 

thank you for your reply.

I tried to build a sample app for you. I copied my solution, renamed the solution, and removed all unneeded parts. Compiled & run => no error
I thought, ok it must have something to do with the parts I removed from my app (multilingual toolkit, sqlite, dapper ....)

So I started with a new copy, just renamed the solution, compiled & run => no error!

Long story short, by simply renaming my solution File lets say from "testv3.sln" to "testv3a.sln" the null reference exeption does not occur anymore.

I have no idea what the renaming of the solution file changes in the solution, and why renaming the sln file fixed it.

It now works in my app, except one point:
In my app I used the property MinimumPreficCharactes (set to 50), because I do not want to display a filtered list. Unfortunately the autohiding mechanismen of the suggesstion box does not work when this property is set. OnElementChanged seems not to be called when MinimumPrefixCharacters is set.

Best regards,

Thomas

Rabhia Beham Kathar Mideenar [Syncfusion]
Replied On August 20, 2019 09:40 AM UTC

Hi Thomas,

We have modified the sample as per your requirement. Please have the sample from the below link,

Sample Link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/CustomRenderer_2-1957361934

Please check with the sample and let us know if you have any concern.

Regards,
Rabhia Beham K. 


nvrsttl
Replied On August 20, 2019 01:16 PM UTC

Hi Rabhia Beham,

thank you for the sample. I already wondered why in the CustomRenderer Control.IsDropDownOpen is set back and forth, that just do the same in case the string is not empty solves the problem is great. I do not understand it, but it works.

Best regards,

Thomas

Muneesh Kumar G [Syncfusion]
Replied On August 21, 2019 06:54 AM UTC

Hi Thomas,  
 
Glad that the issue has been resolved and please get back to us if you need any other assistance.  
  
Regards,  
Muneesh Kumar G 
 


nvrsttl
Replied On January 23, 2020 01:58 PM UTC

Hi,

the solution (auto hide suggestion box, when something is typed into the box) worked using the custom renderer until updating to 17.4.0.40 of SfAutoComplete. Starting with 17.4.0.40 the onscreen keyboard is only displayed once, when it once was hide by focusing an other element it is not displayed again. This happens on Android 8 (real device and emulator) but not on Android 10 (9 not tested).

Could you please check this? 17.3.x and 17.4.0.39 version did not have this problem.

Best regards,

Thomas

Hemalatha Marikumar [Syncfusion]
Replied On January 24, 2020 10:00 AM UTC

Hi Thomas, 
 
Thanks for your update. 
 
We have ensured the reported scenarios even with 17.4.0.40 release version and Android device versions 7 and 8, we were unable to reproduce the issue from our side and it is working fine as the previous one. We have also attached the sample and recorded the screenplay for the same for your reference. Please find the sample from the below link. 
 
 
 
Please let us know if you have any concerns on this. 
 
Regards, 
Hemalatha M. 


nvrsttl
Replied On January 29, 2020 03:44 PM UTC

Hi Hemalath,

sorry, it took me a while to find out why your sample is working and my app produces this problem with the updated SfAutoComplete control.

To reproduce:
Remove DisplayMemberPath="Name" DataSource="{Binding EmployeeCollection}" properties from the xaml

I have a simple list as the datasource of the SfAutoComplete control:
In constructor of MainPage
autoComplete.DataSource = new ObservableCollection<String>();

In "Handle_ValueChanged" I have the following code, to populate the control with a list of the last search patterns

var list = ((ObservableCollection<String>)autoComplete.DataSource);
            // add current search if list is empty
            if (list.Count == 0)
            {
                list.Add(autoComplete.Text);
                return;
            }
            // do not add search if last search starts with current search
            if (list[0].StartsWith(autoComplete.Text)) return;
            // replace last search if current search starts with same pattern
            if (autoComplete.Text.StartsWith(list[0]))
            {
                list.Remove(autoComplete.Text); // make sure pattern is not multiple times in list
                list[0] = autoComplete.Text;
            }
            else
            {
                list.Remove(autoComplete.Text); // make sure pattern is not multiple times in list
                list.Insert(0, autoComplete.Text);
            }

This way, the onscreen keyboard does not show up after the first entry of a search.
(Start the app, klick in the control, onscreen keyboard is displayed, type something, click somewhere on the screen to hide the keyboard, click in the control again, keyboard should display, but it doesn't)
As mentioned this started to happen beginning with version 17.4.0.40

I downgraded SfAutoComplete in your sample to 17.4.0.39 this works fine, you can enter a search phase, hide the keyboard click in the control again, keyboard is displayed. This way it also worked on 17.3.x

Hope this helps, maybe adding / changing items in the list in ValueChanged is not a good idea, but it worked the versions before.

Best regards,

Thomas

Hemalatha Marikumar [Syncfusion]
Replied On January 31, 2020 12:27 PM UTC

Hi Thomas,

 
Thanks for the patience.

 
We could reproduce the reported issue with the changes provided in the last update. We have internally fixed the reported issue "The Keyboard does not shown when the Text has been set in the ValueChanged Eventand the patch files can be downloaded from the following location.  
 
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment  
(OR)

 
(OR)
  
Assembly Version: 17.4.0.46 
    
Disclaimer:   
  
Please note that we have created this patch for version 17.4.0.46 specifically to resolve the following issue reported in this incident. If you have received other patches for the same version for other products, please apply all patches in the order received  
   
Note: Please clear the NuGet cache, before using the latest one.
   
   

The fix will be included in weekly nuget release which is expected to be rolled out on February 11, 2020. 
  
Regards, 
Hemalatha M. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon