Tips for sending information to PrimeVue MenuItems

My PrimeVue Menu setup looks like this:

<template>
  <div class="">
    <label class="text-slate-500 text-sm">Doctor Name</label>
    <div class="text-sm">{{ appointment.doctor.name }}</div>
  </div>
  <div>
    <span>
    <a href="#"><i class="pi pi-ellipsis-v" @click="toggle"></i></a>
    </span>
    <Menu ref="menu" :model="items" :popup="true" />
  </div>
</template>
export default {
  data() {
    return {
      items: [{
          label: 'Reschedule',
          command: (event) => {
            this.rescheduleVisible = true
          },
        },
        {
          label: 'Mark Completed'
        },
        {
          label: 'Cancel Schedule'
        },
        {
          label: 'Generate Bill'
        },
        {
          label: 'Set Reminder'
        },
        {
          label: 'Send Message'
        },
      ]
    },
  },
  methods: {
    toggle(event) {
      console.log(event)
      this.$refs.menu[0].toggle(event);
    }
  }
}     

I have integrated this menu into an appointment listing. When the Reschedule menu item is clicked, I aim to retrieve the corresponding appointment ID to pass it to a modal popup that becomes visible by setting rescheduleVisible as true, displaying details about the appointment. How can this be achieved?

The modal layout is presented below:

<Dialog v-model:visible="rescheduleVisible" modal header="Reschedule" :style="{ width: '30vw' }">
  <div class="bg-white dark:bg-gray-800 sm:rounded-lg">
    <div class="p-2 text-gray-900 dark:text-gray-100">
      <div class="grid grid-col-1 gap-3">
        <div class="p-2">
          <div>
            <InputLabel for="appointment_time" value="Date and Time" />
            <Calendar inputId="appointment_time" v-model="form.appointment_time" :showTime="true"
              :showSeconds="false" hourFormat="12" />
          </div>
        </div>
        <div class="p-2">
          <div>
            <InputLabel for="doctor" value="Doctor" />
            <Dropdown v-model="form.doctor_id" :options="doctors" optionLabel="name"
              optionValue="id" placeholder="Select Doctor" :filter="true" />
          </div>
        </div>
      </div>
      <div class="mt-3">
        <div class="flex justify-end">
          <PrimaryButton class="ml-2" :class="{ 'opacity-25': form.processing }"
            :disabled="form.processing">
            Reschedule
          </PrimaryButton>
        </div>
      </div>
    </div>
  </div>
</Dialog>

Edit: Appointment Listing

https://i.sstatic.net/t2MDu.png

Answer №1

One suggestion I have is to incorporate a popup into your template that will only be visible if the variable rescheduleVisible is set to true. However, it is important to note that you must first define the rescheduleVisible variable in your data object. Without this definition, Vue won't recognize it as a reactive variable and won't know how to watch for changes.

data() {
  return {
    rescheduleVisible: false,
    items: [...

Answer №2

If I understand your situation correctly, you have a list of appointments with nested menus for each appointment. When a user clicks on a menu item, you want to open a modal and pass the ID of the current appointment.

A possible solution could be:
It's unclear if there is a built-in way to pass information about the current item in the loop to the Menu component. However, you can implement a workaround using alternative logic-

Assuming your template structure resembles this:

<div v-for="appointment in appointments">
  <div  class="">
    ...
  </div>
  <div>
    ...
    <a href="#"><i class="pi pi-ellipsis-v" @click="toggle"></i></a>
    ...
    <Menu ref="menu" :model="items" :popup="true" />
  </div>
</div>

You can create a data variable to store the selected appointment id-

data() {
  return {
    selected: null,
  }
}

In the toggle method, you can pass the current appointment's id:

<a href="#"><i class="pi pi-ellipsis-v" @click="toggle($event, appointment.id)"></i></a>

The toggle method will then set the selected appointment id from the parameter:

toggle(event, appointment_id) {
  this.$refs.menu[0].toggle(event);
  this.selected = appointment_id
},

Now, when a child element is clicked, you can open the modal and pass the selected appointment's ID stored in the selected variable. Upon closing the modal, remember to reset the selected variable.

This may not be the most conventional approach, but it should help you utilize PrimeVue's Menu component within a loop effectively.

Answer №3

If you want to toggle the menu, simply pass the id along with it

 <Button @click="toggleListOptions($event, item._id,)" icon="pi pi-ellipsis-v" size="small" />

Then capture the id for further processing

function toggleListOptions(event: Event, id: string) {
    console.log("🚀 ~ toggleListOptions ~ id:", id)
    menuListOptions.value.toggle(event)
}

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

Revise Bootstrap accordion setup

I currently have a Bootstrap accordion set up on my website using Bootstrap 4.1.0 <div id="accordion" class="mt-3"> <div class="card"> <div class="card-header bg-dark text-white" id="headingOne"> <h5 class="mb-0 f ...

Invoking a C++ dll in the renderer process of a Node.js application with Electron using node ffi

As I work on developing a windows application using electron, my goal is to utilize the ffi-napi to invoke C++ .dll methods. However, I am facing a challenge with the "Passing_Dll.js" file, where the label with id "GenName" is not being updated when clicki ...

Challenges encountered when using node.js to write binary data

I've been attempting to write the binary body of a request to a file, but I'm encountering some issues. Although the file is successfully created on the server, I'm unable to open it and am receiving a 'Fatal error: Not a png' mess ...

What is the reason behind bower installing packages twice?

Whenever I use Yeoman to install packages, which is powered by Bower in the background, I notice that each package gets duplicated... The first copy is placed in the project root under the components folder. The second copy goes inside the app/components ...

What steps should I take to resolve a 'Missing environment variable' issue in the Sanity platform?

No matter what I've tried, I can't seem to fix the error that keeps occurring. An uncaught error is popping up, saying that the environment variable NEXT_PUBLIC_SANITY_DATASET is missing. http://localhost:3333/static/sanity-5377bc10.js:4605 ...

Storing and accessing a rootScope parameter and its value in Angular JS cache

Is there a way to cache this basic object ($rootScope.config.app_genres) that I set via $http for a specific amount of time? $http.get($rootScope.config.app_ws+'get/genres',{},{cache:true}).success(function(response) { $rootScope.config.app ...

Strange behavior observed in the Datepicker, possibly linked to the blur event

I'm facing a challenge with the Datepicker feature. When I blur, the calendar disappears if the Datepicker was active, but the focus remains on the input field. As a result, I am unable to trigger the Datepicker again by clicking on the input field. T ...

What is the best way to establish a default rejected promise behavior for all of my Express middleware functions?

Using promises within express middleware and wanting to switch to async/await methods. app.get('/data1',async function(req,res) { data = await getData1(); // Error occurs here res.send(data) }) app.get('/data2',async function(r ...

Chartjs-node in conjunction with prebuilt canvas is persistently generating 'Cairo not detected' errors

Currently, I am utilizing chartjs-node for creating charts. On my local (Windows) machine, the node.js code works flawlessly, likely due to having windows-build-tools with the cairo package installed. However, when attempting to compile on my remote (Linu ...

React is throwing an error because a unique key is missing for the map iteration

I'm encountering an issue with missing a key prop in my map iteration. I have nested maps and can't figure out where the missing key is located. Could someone please assist me? displayData() { const { data, index } = this.state; let sortedDa ...

Retrieving dynamic id values from input fields using jQuery

Is there a way to retrieve the values from input fields with changing IDs in a jQuery function? <input type="text" id="a_8" name="a_8" value="12"> <input type="text" id="b_8" name="b_8" value="22"> <button type="button" class="btn btn-suc ...

JavaScript's menu button has a callback function assigned to it

The definition can be found below. var CMenu = cc.Sprite.extend({ onClickCallback: null, onClick: function (callback) { this.onClickCallback = callback; }, handleTouches: function (touch, evt) { (this.hovered && this.onClickCallback) &am ...

How do I retrieve the content within this HTML element using JavaScript based on its ID?

Is there a way to extract the string from this specific HTML element using JavaScript? The element has an id of recItemString_GPLA\|input, and within it, there is a string containing "qty" that I need to retrieve. Upon inspection of the element, the f ...

What is the best way to choose a piece of code in Vue.js that will create a looping effect?

Is it possible to prevent the legend tag from following the loop by writing it in the same block as the form tag? var app = new Vue({ el : '#container', data : { menus : [ {formm : "Name&qu ...

retrieve the php variable value and display it in an input field using javascript

I am looking to combine the variable $variable with the input value using JavaScript $variable= file_get_contents('./env.txt'); <select id="customer_id" name="customer_id" w300 required pj-chosen" data-msg-required=&q ...

Identify the specific tab that initiated the request

Here's a puzzling question that may not have a straightforward solution, but I'm willing to give it a try. Recently, I developed a brilliant one-page application where each open tab "registers" itself with the server upon startup, indicating its ...

Sharing data from AJAX calls in Vue using vue-resource

After using Vue resource, I'm attempting to create an AJAX call that is based on the data received from a prior AJAX call. I have successfully bound the data fetched from /me to the userDetails prop. However, when trying to pass userDetails.id into t ...

Encountering build:web failure within npm script due to TypeScript

Our project is utilizing the expo-cli as a local dependency in order to execute build:web from an npm script without requiring the global installation of expo-cli. However, when we run npm run build:web, we encounter the following exception. To isolate th ...

Tips for accessing user-defined headers within CORS middleware

I've developed a CORS middleware utilizing the CORS package. This middleware is invoked before each request. Here's how I implemented it: const corsMiddleware = async (req, callback) => { const { userid } = req.headers|| req.cookies {}; l ...

Displaying JSON data dynamically by iterating through it in a loop

While working with JSON data in a loop, I noticed that the code quality does not meet my expectations. I have a feeling that I might be missing something in my approach. $(function(){ $.getJSON('data.json', function(data){ let content ...