Single-page website experiencing Bootstrap problem

I've been struggling with creating a card component for array elements in Vue Bootstrap. The goal is to open a modal specific to the clicked element when the header of the card is clicked. However, the issue I'm facing is that clicking on any header opens multiple modals, showing all array elements at once. How can I modify my code to only open the modal of the particular array element that was clicked? Here's the snippet I'm currently working with:

     <div
        v-for="(value,key,index) in flowers"
        :key="value"
        class="card"
      >
        <div v-b-modal.modal-1 class="card-header" >
          <div>
            {{ value.name }}
          </div>
          <b-modal id="modal-1" title="Flowers">
            <p class="my-4" v-for="item in value.petals" :key="item">{{item}}</p>
          </b-modal>
        </div>
     </div>

Answer №1

Each modal must have a unique id, as currently you are assigning the same id to all modals, causing them all to open when clicked on. This results in multiple modals with the id modal-1. To resolve this issue, ensure that each modal has its own distinct id.

In the code snippet below, the key is being utilized, but if there is a different unique value for each entry, it is recommended to use that instead.

<div
  v-for="(value, key, index) in flowers"
  :key="value"
  class="card"
>
  <div v-b-modal:[`modal-${key}`] class="card-header" >
    <div>
     {{ value.name }}
    </div>
    <b-modal :id="`modal-${key}`" title="Flowers">
      <p class="my-4" v-for="item in value.petals" :key="item">{{item}}</p>
    </b-modal>
  </div>
</div>

Answer №2

It's worth noting that all of your modals currently share the same id, id="modal-1". To differentiate between them, you can leverage the top v-for key as an id instead. For instance, you could use id="modal-{{key}}".

Here is a sample implementation:

<tbody>
  <tr v-for="item in items" v-on:click="select($event)" id="{{ item.ID }}">
     <td class="cod">{{ item.ID }}</td><td class="name">{{ item.NAME }}</td><td class="cat">{{ item.CATEGORY }}</td><td class="price">{{ item.PRICE }}</td>
  </tr>
</tbody>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can a small white pop-up be triggered by clicking a button?

While exploring the website , I noticed that clicking on Availability Zones opens a small window with text on the right side of the page. Is it possible to achieve a similar feature on a leaflet map without using JavaScript? This functionality would be tri ...

Sorting an array of strings in JavaScript with the help of another array of strings

I am looking for a way to rearrange array1 based on array2. var array1 = ["cat","dog","mouse","elephant","ant","cow","goat","hen"]; var array2 = ["mouse","cow","goat"]; Expected output: var another_array = ["mouse","cow","goat", "bird"--- then rest of ...

Developing a concealed Repeater element that is retained in the source code for utilization in JavaScript tasks

I am currently working on a setup with two repeaters: one that is displayed when the page first loads, and another that I want to keep hidden until a link called "Add Stuff" is clicked. My goal is to use JavaScript to make this second repeater visible upon ...

What is the best way to showcase my customized license plate on the following page?

I need help with incorporating my number plate builder into a website. I have utilized JQUERY and JAVASCRIPT for the styling aspect, but now I want to display the designed plate on the next page. Can someone guide me on how to achieve this using PHP, JQUER ...

Tips for creating a vertical Angular Material slider with CSS

Attempting to modify the angular material directive to render vertically has been a challenge. I experimented with using transform:rotate in the CSS, however, it resulted in the slider behaving and rendering differently. md-slider { position: absolute ...

How to Achieve Seamless Vertical Scrolling Through Clicking a Button

I'm currently working with Bootstrap 4 Modal and have removed the Overflow-Y (ScrollBar) to enhance the design. However, I've also incorporated a function with two buttons (Up & Down) using JavaScript to facilitate easier navigation for users. Th ...

Retrieve the list of device tokens for the APNS service

Is it possible to retrieve a list of all device tokens on which my app is installed through an APNS endpoint? I am aware of the feedback service that provides the status of devices to whom messages are sent, but I believe this is only after the message ...

Issue with xsl:include functionality in a Firefox extension

I've been working on a Firefox extension that utilizes XSL transformations with no issues. However, I encountered a problem when trying to perform an xsl:include from the XSL stylesheet. Upon importing the XSL stylesheet containing an xsl:include stat ...

Error encountered while deploying React app on Netlify due to absence of build scripts

I recently deployed a React app on Netlify from GitHub. Unfortunately, the deployment status showed as failed with the following error: Mar 27: Failed during the stage of 'building site': Build script returned a non-zero exit code: 1 I als ...

Creating a mandatory and meaningful text input in Angular 2 is essential for a

I am trying to ensure that a text material input in my app is mandatory, with a message like "Please enter issue description." However, I have noticed that users can bypass this by entering spaces or meaningless characters like "xxx." Is there an npm pac ...

Tips for sending a localstorage value as a parameter in an axios request

Currently, in my React app, I am using Express to handle all of my database queries. One thing I am attempting to achieve is passing the user id stored in local storage into a post request. This is necessary for my application since it revolves around use ...

Positioning an item atop the curved exterior of a spinning Globe

I am new to posting here, so bear with me as I explain my issue. Whenever I place an object on a rotating sphere's surface, it becomes offset as the sphere continues to rotate. I have attempted to adjust the position back to the mouse, but unfortunat ...

Is there a way for me to specifically show just the initial image contained in the images[] array within the json data?

{"status": true, "data": {"basic": {"dob": "2018-02-02", "gender": "male", "contact": {"address": null}, "is_new": false, "is_email_verified": false, "is_phone_verified": false}, "listings": [{"pid": 109, "category": {"name": "Education"}, "location": {"l ...

A guide on transforming a JSON object representing an HTML element into a live HTML element for display on a webpage using C#, JavaScript, or jQuery

I am looking to retrieve a JSON object from a database and convert it into HTML format. Here is an example of the JSON structure: {"input":{ "name":"fname", "type":"text", "placeholder":"Ente ...

tool for showcasing data on a webpage with a specific layout

Which chart library is best suited for presenting data in the formats shown in the images below? Can HighCharts handle these formats? Does Google Charts allow for a combination of bubbles and lines? ...

Obtain Relative URL with the help of Selenium using the PhantomJS driver

Utilizing Selenium along with the Phantom JS driver, I am attempting to load an HTML page and extract all of the HREF links from it. The issue arises when PhantomJS provides absolute URLs after resolving them entirely. My specific requirement is to extrac ...

CSS Style in Safari does not conceal Div on Tailwind

When switching the screen from desktop to mobile in ReactJS/Tailwind, I have hidden certain images using the following code: <div className="flex shrink flex-row justify-between w-[60%] h-[25%] sm:w-[95%] sm:h-[52%] mb-[-10px] mt-[-15px] lg:mt-0&qu ...

Issue with Angular Factory not being invoked

I am currently using a tutorial to create a MEAN app with Google Maps. However, I have encountered an issue where the map is not appearing on the page. Surprisingly, there are no errors in the browser console and even when debugging with node-inspector, I ...

What is the process for creating a local repository for Node.js npm?

When it comes to the building process in node js, there are a few goals that need to be called: Begin by calling npm install, which creates a folder called node_modules and places all dependencies from package.json into it. [for UI development] Execute a ...

Issue: Module 'curl' is not located at Function.Module._resolveFilename (module.js:489:15)

After installing node.js using the Windows installer, I noticed that the folder structure created was C:\Program Files\nodejs\node_modules\npm\node_modules. It seems like all the module folders are in the last node_modules director ...