Setting global default ajax setting makes all select2 controls use ajax


#1

Use-case: Set a default of 250ms before searching on ajax select2 drop downs. Any non-ajax drop down should ignore this setting.
Example: http://jsbin.com/rojegadaye
Expected: Drop down does not use ajax, should show options from HTML
Actual: Select2 attempts to query current page for ajax results

I thought it might be related/fixed with https://github.com/select2/select2/pull/4364 however testing with 4.0.6-rc.0 & 4.0.6-rc.1 exhibit the same behavior.

Am I misinterpreting how the global defaults should be used?

Thanks


#2

I’m not sure if this is a bug or not, but I was able to “fix” it by adding the following line:
$.fn.select2.defaults.set('ajax', null);


#3

Hey, thanks John. While the fix does remove the issue it’s also removing the desired behavior I’m after. I’m looking to set a global default for all select2’s on my site that use ajax and searching. I want them all, by default, wait 250ms before hitting the server. Once you set (‘ajax’,null) it’s effectively putting the settings back to the default initialization. This will cause searching to execute without a delay. The other by-product is that it’s also forcing any select2 that doesn’t use ajax at all (local data in html) to try and use ajax. Which, I’m thinking might be a bug.


#4

Yes, it certainly seems like a bug. Your jsbin only had one type of Select2 widget (the HTML kind), so I didn’t realize you needed to mix and match them.

I would suggest you open an issue on the Select2 GitHub about this.