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. Image for the cookie policy date

Determining if autocomplete value is a match during change event

Hello,

When the autocomplete change event fires, I would like to find out if the autocomplete value is not found in the data source (i.e., the value is not an exact or 'contains' match with the data source).

Is there a way to do this using a model property?  Or would I need to create a function to test this each time the change event fires?

Thank You,
Randy

4 Replies

HP Harikrishnan P Syncfusion Team November 12, 2015 12:57 PM UTC

Hi Randy,


Thanks for contacting Syncfusion support.


We maintain an internal variable called “noresult”. This variable returns a boolean value to indicate whether the autocomplete value is matched with the datasource or not. If the value is matched with the datasource then false will be returned. If it is not matched, then true will be returned. In the “keyup” event, you can use this variable to identify whether the value is matched with the Autocomplete datasource or not. Please refer the following code,



            //Object for Autocomplete created

            autocompleteObj = $('#flowerslist').data("ejAutocomplete");

            $('#flowerslist').on("keyup", function () {

                //retruns whether the value is present in the datasource or not

                console.log(autocompleteObj.noresult);

            });



We have attached a sample for your reference, please check it


http://jsplayground.syncfusion.com/m0l5vwd0


If you need any other assistance, please get back to us and we will be happy to help you.


Regards,

HariKrishnan



RC Randy Craven November 13, 2015 04:19 AM UTC

Thank You, HariKrishnan,  that is what I was looking for.

I would like to ask another question,

Is it possible to determine if there is exactly one match between the autocomplete and the datasource?

Once it is determined that there is exactly one match to the datasource, is it then possible to retrieve the "key" from the fields collection for the matched item in the datasource?

Thanking you again,
Randy Craven



RC Randy Craven November 16, 2015 12:52 AM UTC

Hello,

First, I was able answer my question about finding the datasource key from another forum post.  So thank you, there is no need to answer that one for me.

I do have an additional question, once a match has been found in the datasource, is it possible to hide the suggestion list?

Thank you,
Randy 



MM Manikandan Mariappan Syncfusion Team November 16, 2015 03:54 PM UTC

Hi Randy,
 
Query1: Once a match has been found in the datasource, is it possible to hide the suggestion list?
 
You can achieve this requirement by using the hide method in open event. Please refer the below code snippet.


function onPopupOpen(args) {

            this.showSuggestionBox = this._isOpened = true;

            setTimeout(function () {

                if (!autocompleteObj.noresult)

                    autocompleteObj.hide();

            },200);

}



Please find the sample for your reference in JS playground link
http://jsplayground.syncfusion.com/ocftudgl
Regards,
M.Manikandan

Loader.
Up arrow icon