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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Determining if autocomplete value is a match during change event

Thread ID:

Created:

Updated:

Platform:

Replies:

121118 Nov 12,2015 12:39 AM UTC Nov 16,2015 03:54 PM UTC JavaScript 4
loading
Tags: ejAutoCompleteTextBox
Randy Craven
Asked On November 12, 2015 12:39 AM UTC

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

Harikrishnan P [Syncfusion]
Replied On 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


Randy Craven
Replied On 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


Randy Craven
Replied On 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 


Manikandan Mariappan [Syncfusion]
Replied On 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

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.

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

;