Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a dynamic tooltip in a select option using vue.js?

I have an array declared in vue.

sourceSelect: [
    { text: "Option 1", value: "1", title: "First tooltip" },
    { text: "Option 2", value: "2", title: "Second tooltip" },
    { text: "Option 3", value: "3", title: "Third tooltip" }
],

I have a select element in my markup:

<select class="form-group col-sm-8" v-on:change="showOptions" v-model="sourceSelected" data-toggle="tooltip" data-placement="top" data-html="true">
    <option v-for="source in sourceSelect" v-bind:value="source.value" title={{source.title}} >{{source.text}}</option>
</select>

The drop-down shows the options, and shows a tooltip, but unfortunately not the title values setup in the array - rather it shows {{source.title}}. Is there any way of setting up the values for a title attribute dynamically in this way? I'm using vue.2.6.10

like image 494
Edwardo Avatar asked Aug 21 '20 13:08

Edwardo


People also ask

How do I create a dynamic tooltip?

Here's how: Drag the calculated field to the appropriate tooltip and you'll see an ATTR dimension pill with a tooltip logo in the Marks card. Insert the ATTR budget and adjusted inflated gross calculated fields into its corresponding tooltip as seen in Image 6. After that, you're dynamic tooltip should work!

How to implement tooltip in Vue?

To create a tooltip using the component approach, we can simply create a button and put the ID in the target attribute. In the code above, we created a button called b-button and gave it a specific ID, tooltip-target-1 .


1 Answers

You should bind as you did with value attribute :

 <option v-for="source in sourceSelect" v-bind:value="source.value"  v-bind:title="source.title" >{{source.text}}</option>

Vue.config.devtools = false;
Vue.config.productionTip = false;

new Vue({
  el: '#app',
  data() {
    return {
      sourceSelect: [{
          text: "Option 1",
          value: "1",
          title: "First tooltip"
        },
        {
          text: "Option 2",
          value: "2",
          title: "Second tooltip"
        },
        {
          text: "Option 3",
          value: "3",
          title: "Third tooltip"
        }
      ]
    }
  }
})
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>


<div id="app" class="container">
  <select class="form-group col-sm-8" data-toggle="tooltip" data-placement="top" data-html="true">
    <option v-for="source in sourceSelect" v-bind:value="source.value" :title="source.title">{{source.text}}</option>
  </select>

</div>
like image 141
Boussadjra Brahim Avatar answered Oct 11 '22 07:10

Boussadjra Brahim