harvesthq / chosen

Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
http://harvesthq.github.io/chosen/
Other
21.85k stars 4.1k forks source link

Is there a way to overwrite container_mousedown in 1.7 version? #3120

Closed nathipg closed 3 years ago

nathipg commented 3 years ago

Hello!

I want to change chosen to only show results when user type, not when user click on the container. For that, I though about overwrite container_mousedown to work as I need. Is is possible? I see chosen is returned as a function, so I couldn't see an obvious way to do it.

nathipg commented 3 years ago

If anyone needs this in the future, I have done like this:

select.on('chosen:showing_dropdown', function (e, cfg) {
    if(cfg.chosen.search_field.val() == '') {
      cfg.chosen.results_hide();
    }

    cfg.chosen.search_field.off('keyup.chosen.checkshow');
    cfg.chosen.search_field.on('keyup.chosen.checkshow', (event) => {
      if(cfg.chosen.search_field.val() == '') {
        cfg.chosen.results_hide();
      } else if(!cfg.chosen.results_showing) {
        cfg.chosen.results_show();
      }
    });
});