Giter VIP home page Giter VIP logo

Comments (3)

 avatar commented on May 18, 2024

Hello Luciano,

There two methods on of them is onSelect and another is onChange

onSelect: function (value, data) {

},
onChange: function(value, data) {
if (data == -1) {
…..
}
},

Thanks

From: Luciano Mammino [mailto:[email protected]]
Sent: Thursday, September 06, 2012 4:36 PM
To: devbridge/jQuery-Autocomplete
Subject: [jQuery-Autocomplete] Detect when the input value changed if the user clicked a suggestion or not (#6)

Is there a built-in way to detect, when the input changes, whether the user clicked a suggestion or not?

I looked at the code and i found the field value is set before calling the onSelect callback.

        //...

select: function (i) {

    var selectedValue, f;

    selectedValue = this.suggestions[i];

    if (selectedValue) {

        this.el.val(selectedValue);

        if (this.options.autoSubmit) {

            f = this.el.parents('form');

            if (f.length > 0) { f.get(0).submit(); }

        }

        this.ignoreValueChange = true;

        this.hide();

        this.onSelect(i);

    }

},

       //...

If the onSelect is called before the this.el.val(selectedValue) one would easily detect if the user selected a suggestion on change doing something like this:

$('.autocomplete').autocomplete({

serviceUrl : '/ajax/autocomplete',

onSelect : function(value, data, input)

{

    input.data('suggestionClicked', true);

}

});

$('.autocomplete').change(function(){

if($(this).data('suggestionClicked')

{

      // ...

}

});

Please let me know if there's a built-in proper way to do so

Thanks


Reply to this email directly or view it on GitHubhttps://github.com//issues/6.

from jquery-autocomplete.

lmammino avatar lmammino commented on May 18, 2024

Thanks @Vytautas-Pranskunas .
Anyway the onChange calback is just a wrapper for the input default change event callback.
I mean It's called before the onSelect... so my problem persists...

from jquery-autocomplete.

lmammino avatar lmammino commented on May 18, 2024

Now i digged further into your code and discovered that your onChange function will pass a -1 as value for the data parameter when nothing has been selected. So this way I'm able to detect whether the user selected a suggestion or not.

Closing this issue. Thanks anyway!

from jquery-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.