Thompson
Thompson

Reputation: 2000

jQuery "Chosen" on-filter event?

I want to run a function whenever the search input box is changed in chosen (jquery dropdown plugin). But unable to find such event neither in their documentation nor on the net. Does anyone have experienced or have idea how to call some code whenever search is done in Chosen?

I tried placing the jquery .on('change' event on the textbox but it didn't work.

I wrote

$(".chosen-search input").on("change", function(e) {
     //console.log($(this));
});

Upvotes: 1

Views: 2763

Answers (3)

Andriy Vasylytsya
Andriy Vasylytsya

Reputation: 11

Chosen js filters dropdown list onkeyup event. This snippet would work better:

$(document).on('keyup', '.chosen-search input', function() {
    console.log('filtered');
})

Upvotes: 1

tyler.frankenstein
tyler.frankenstein

Reputation: 2354

I had to "double" wrap the on to get the input event to fire on the Chosen text field search box:

  $('#my-chosen-input').on('chosen:showing_dropdown', function() {
    $('.chosen-search input').on('input', function() {
      // The text has changed, do something...
    });
  });

Upvotes: 4

Kornelito Benito
Kornelito Benito

Reputation: 1107

    $(".chosen-search").change(function(){

            console.log("changinn");
        });

This should work

Upvotes: 1

Related Questions