3

bootstrap-select for bootstrap 5.3

 1 month ago
source link: https://gist.github.com/mattymatty76/c996d3b77f298b2ec133be59992df9d4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

bootstrap-select for bootstrap 5.3 · GitHub

Instantly share code, notes, and snippets.

Clone this repository at <script src="https://gist.github.com/mattymatty76/c996d3b77f298b2ec133be59992df9d4.js"></script>
Save mattymatty76/c996d3b77f298b2ec133be59992df9d4 to your computer and use it in GitHub Desktop.
bootstrap-select for bootstrap 5.3

Thanks for this @mattymatty76 - works great for me. Can I just ask what the reason is for checking hasClass('ajaxselect')? I found that it wasn't working for my ajax-select as I didn't have that class in my select element (I was initialising using JS). Once I added it in everything worked as expected, but this means it is not backwards-compatible and others may fall foul.

Author

I'm glad it's working.
I updated that library, customizing it, because the original version didn't work: so I adapted it to my bootstrap 5.3 project and now I can use bootstrap-select without problems. Regarding the ajaxselect class, I inserted it in case ajax-bootstrap-select is used because it uses bootstrap-select: in this case is useful to force the refresh of the list which, if very long, was not drawn correctly: at least in my case.
About backwards-compatible I think it's not a problem because if you need to use bootstrap-select in old version (bootstrap 3 or bootstrap 4) you can use old bootstrap-select; otherwise in bootstrap 5 you don't have an alternative because the current official version doesn't work (bootstra-select release v1.14.0-beta3) and this is the reason why I have updated/alterated that library in a new custom version for my project, but without the ambition of replacing the original project or library: it was something I did for myself and I published it thinking it could be useful for others too.

Thank you @abeverley

Author

Thanks for this @mattymatty76 - works great for me. Can I just ask what the reason is for checking hasClass('ajaxselect')? I found that it wasn't working for my ajax-select as I didn't have that class in my select element (I was initialising using JS). Once I added it in everything worked as expected, but this means it is not backwards-compatible and others may fall foul.

@abeverley if you have a form with some components including an ajax-bootstrap-select and a simple bootstrap-select, you can't discriminate between them if you don't put a class like ajaxselect at the component ajax-bootstrap-select: this because if you don't put a check and always apply this.setSize(true) to all selects, slows everything down tremendously especially if the simple bootstrap-selects are large: since simple bootstrap-select is loaded just one time when you open the form, you don't need to call setSize; whereas an ajax-bootstrap-select changes everytime you type a char, so you need to call setSize to force it to redraw correctly

@mattymatty76 I appreciate you. It is working for me.

Author

Thanks to you it's a pleasure


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK