Selectize.js: Avoid opening dropdown after item is removed

Created on 13 Oct 2015  路  14Comments  路  Source: selectize/selectize.js

Is it possible to avoid having the dropdown being opened after an item is removed? I've tried this.blur in onItemRemove. But it only works if I put it in a timeout which is not ideal.

confirmed enhancement no-issue-activity

Most helpful comment

I also have this problem. Hacks only worked with remote source, not without remote source.

The issue can be fixed by adding openAfterItemRemove option and support for it. With that option it is possible to configure Selectize to not open dropdown after item removal. It defaults to true, i.e. not change current behavior.

Please see the pull request I submitted: https://github.com/selectize/selectize.js/pull/1234

All 14 comments

+1

Yeah, it works with a (big) timeout of 200 ms... and also not always.. any hints?
tried it with

...
closeAfterSelect: true,
onItemAdd: function() {
  this.close();
  $("#btnSearch").focus();
},
onOptionAdd: function() {
  setTimeout(function() {
    this.blur();
    $("#btnSearch").focus();
  }.bind(this), 200)
},
...

Is there no better solution available?

I've put quite a lot of time on this issue trying different solutions but in the end I just gave up and let it open after removal of item. The timeout solution as I remember it caused some other problems.

This hack works in my case:

var hackToClose = false;
selectize.on('item_remove', function(value, $item) {
    hackToClose = true;
});
selectize.on('dropdown_open', function($dropdown) {
    if ( hackToClose )
        selectize.close();

    hackToClose = false;
});

I also have this problem. Hacks only worked with remote source, not without remote source.

The issue can be fixed by adding openAfterItemRemove option and support for it. With that option it is possible to configure Selectize to not open dropdown after item removal. It defaults to true, i.e. not change current behavior.

Please see the pull request I submitted: https://github.com/selectize/selectize.js/pull/1234

@panupetteri : do you know when your work is going to be merged and released?

No idea. Most likely not soon: it is one of 111 pull requests to the Selectize.js repository at the moment.

For now, I'm using manually modified version that includes my changes to Selectize.js.

I really need this feature but I don't enjoy having custom version of a dependance because I am using gulp + bower to build my app. I have seen that with selectize it is possible to develop plugins, I was wondering if it would be a good idea to start developing a plugin that take your code, like that I would still use official selectize release and I will only add my brand new pluggin, what do you think about that?

If the plugin API is powerful enough, that sounds like a good way to proceed.

OK thanx I think I am going to give it a try.

Almost a year later. Who wants the dropdown to pop open on deleting an item anyway? Such an easy fix, why hasn't it been done?
selectize.js (standalone), line 3043 (as of today), add:
self.close();
Takes 30 seconds to add.

I'm having this behaviour any time I call refreshOptions after adding/removing options. It seems to trigger the open on selectize. Really anoying.

I guess my only option is to give @itsdeluxe solution a try.


My Bad, if anyone gets here having my use, declaration for refreshing options is refreshOptions(triggerDropdown) so calling it refreshOptions(false) avoid openning the dropdown.

Hi facing a similar issue, is there anyway we can remove the focus from the dropdown on removing item?

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreypopp picture andreypopp  路  15Comments

oswaldoacauan picture oswaldoacauan  路  21Comments

nesl247 picture nesl247  路  37Comments

CarlosLlongo picture CarlosLlongo  路  18Comments

AndyBean picture AndyBean  路  15Comments