Vue: bootstrap-select creates button with title={{option.value}} attribute which is no longer allowed
Vue throws an "Error compiling template" when trying to use boostrap-select while binding to
https://jsfiddle.net/t0u28xec/
- Set up your HTML file with jQuery 3.3.1, bootstrap 4.1.3, bootstrap-select 1.13.2 and vue 2.2.1 (dev to see the verbose problem description)
- Add a
<select class="selectpicker">to your HTML. - Add one
<option v-for="option in someCollection" v-bind:value="option.id">{{ option.value }}</option>to the select. - Set up the Vue in your JavaScript to bind the above with an empty array for the collection (not sure if it matters much if it's a real collection of objects)
(See the JSFiddle for an example)
Four JavaScript exceptions are thrown by vue.js when using the dev version. It explains that: "Interpolation inside attributes has been removed..." and shows where the problem lies.
Bootstrap-select creates a button and apparently pulls the original
I am not sure what the solution to this is, but wanted to make you aware and open a dialog and hopefully arrive at a good solution.
Bootstrap-select rocks, thank you for your hard work on it! And thank you for considering this issue.
This is happening because bootstrap-select is running before Vue, so Vue sees the bootstrap-select markup with title="{{ s.name }}" set on the button. Your best bet is to remove the selectpicker class and manually call .selectpicker().
I don't have much experience with Vue, but something like this should work: https://jsfiddle.net/caseyjhol/ft5c01p9/7/.
You are correct. The timing problem bit me in another way after I created this issue here; dealing with a refresh issue after I update the empty options array with an AJAX call to an API after the page first loads.)
Both are solved by doing as you suggested, but for others that come here with a similar question in the future, you can take one more step in the "mounted" handler to ensure the selectpicker isn't applied until Vue is completely finished with its own updates after the mounted event by using their $nextTick function to apply selectpicker after it all:
mounted: function(){
this.$nextTick(function(){ $('.my-select-picker-class').selectpicker() });
}.
I wrote an article that covers both issues with both a broken and working example to explain the timing issue in case someone would like to understand better.
Thanks for your help @caseyjhol
@jlitster Can you explain me how it works with vuejs
@khayyak : Please see my write-up at javascriptjedi.com
Especially note the bottom section titled: "Recommendations for using Vue with bootstrap-select:"
I find it easiest to avoid bootstrap-select's naming convention for getting their code hooked up to my select elements and rather explicitly calling it in the Vue "mounted" event and refreshing using $nextTick when it's time to update the options using the explicit elements "ref" or "id" and calling .selectpicker('refresh') explicitly. (The link above will explain in greater detail.)
Hope that helps!
@jlitster thank you very much for response but I have the issue with search input , when open select item I can't find it so I don't know what is the problem. even I add data-live-search = true
cheers
@khayyak Are you talking about something like this? https://jsfiddle.net/7q8fLy4g/22/
@jlitster yes I mean that , should I use same code ?
@khayyak : Yes, feel free to use that code to get you started. I updated it with some HTML and JavaScript comments to hopefully help explain more if you are brand new to Vue and Bootstrap-Select. https://jsfiddle.net/5ujc9vpg/8/
Best of luck to you!
@jlitster thank you very much for this effort . I understand everything you wrote but the problem of the search box still hidden . even I did same steps in your code
@khayyak : If you will post your code in a JSFiddle (or similar site) I am happy to take a look.