question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple dynamic ids in v-b-toggle

See original GitHub issue

Hey 😃, I cannot find how to add multiple dynamically created ids into directive v-b-toggle. I’ve found a solution just for a single dynamic id. I’ve tried this, but none of this works:

v-b-toggle="`id-${name1} id-${name2} id-${name3}`"
v-b-toggle="`id-${name1}.id-${name2}.id-${name3}`"
v-b-toggle="{[`id-${name1}`]: true, [`id-${name2}`]: true, [`id-${name3}`]: true}"

Is there any way how to do it and set more than one modifier dynamically?

The whole problem in short:

<template>
  <div class="super-ultra-toggler">
    <b-button v-b-toggle="{[`id-${name1}`]: true, [`id-${name2}`]: true, [`id-${name3}`]: true}">toggle all</b-button>

    <div v-for="(name, index) in names"
      :key="`name-${index}`">
      <b-button v-b-toggle="`id-${name}`">toggle</b-button>
      <b-collapse :id="`id-${name}`" :visible="false">
        <p>{{ name }}</p>
      </b-collapse>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UltraSuperToggler',
  data() {
    return {
      name1: 'Bob',
      name2: 'Mark',
      name3: 'Lea',
      names: ['Bob', 'Mark', 'Lea']
    }
  }
}
</script>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

8reactions
Hiwscommented, May 12, 2020

Alternatively to the v-model solution you could create a method which takes an array of id’s as a parameter and use the option to emit on root, by looping through the passed in ID’s and emitting for each of them.

<template>
  <b-button @click="toggleCollapses(['collapse-a', 'collapse-b'])">
  Toggle Both Collapse A and B
  </b-button>

  <!-- Elements to collapse -->
  <b-collapse id="collapse-a" class="mt-2">
    <b-card>I am collapsible content A!</b-card>
  </b-collapse>
  <b-collapse id="collapse-b" class="mt-2">
    <b-card>I am collapsible content B!</b-card>
  </b-collapse>
</template>

<script>
  toggleCollapses(ids) {
    ids.forEach((id) => {
       this.$root.$emit('bv::toggle::collapse', id)
    })
  }
</script>
1reaction
tmorehousecommented, May 23, 2020

I just tested in the playground, and it works fine for me: https://codesandbox.io/s/little-pond-hnfci

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically generating directive name in Vue Bootstrap
The way Vue bootstrap does this is by giving the collapsable element an id that matches up to the directive name of the...
Read more >
Toggle | Directives
v-b -toggle is a light-weight directive for toggling the visibility of collapses and sidebars, and includes automated WAI-ARIA accessibility attribute handling.
Read more >
Show / hide columns dynamically
Name Position Office Age Start date Salary Airi Satou Accountant Tokyo 33 2008‑11‑28 $162,700 Angelica Ramos Chief Executive Officer (CEO) London 47 2009‑10‑09 $1,200,000 Ashton Cox...
Read more >
Dynamic Components with Vue's 'component'
Dynamic Components with Vue's 'component' ... piece of your template could be dynamic and switch between one or many components depending on ...
Read more >
Handling Web Tables, Frames, and Dynamic Elements in ...
There are many ways we can handle a web table. ... For example: if id of 'login' field changes dynamically and there is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found