Ajax-Bootstrap-Select: Cannot instantiate an AjaxBootstrapSelect instance without selectpicker first being initialized!
I’m trying to use this awesome plugin in a BS modal but I got this:
Cannot instantiate an AjaxBootstrapSelect instance without selectpicker first being initialized!
a piece of code:
selectPartner = jQuery('.select-partner'); selectPartner.selectpicker({ bindEvent: 'keyup paste' }).ajaxSelectPicker({
I’ve tried wrapping ‘ajaxSelectPicker’ in a setTimout and it seems to work.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (7 by maintainers)
There is option to use $(“select.your-ajax-select-class”), not only id. It works in my case.
@dmazilov 's solution works perfectly.
The reason we were seeing that error was because we call this function multiple times… First time, $(“.your-ajax-select-class”)… works just fine.
However, selectpicker puts the same class on the div it creates around the <select> for its own display
Now the next time we do $(“.your-ajax-select-class”)… It tries to add ajaxselectpicker to the div and it fails.
Hence, $(“select.your-ajax-select-class”) solves the issue