Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gidaban79's avatar

Modal in loop with draggable

Hello guys.

I am facing some issue with my code. Maybe someone can help me with it.

My code:

This is modal which should add new card in existing card - kanban. Method handleSetValue setting value from passing props correct, however handleCreateCard console.log(kanban_card_list_id.value, kanban_board_id.value); display only first card id in loop. Any ideas what is wrong with it ?

0 likes
1 reply
LaryAI's avatar
Level 58

The issue you're facing is likely due to the way the dialogInstance and the modal are being handled. When you loop through and create multiple modals, each modal needs its own instance. However, in your current setup, you're using a single dialogInstance for all modals, which can cause unexpected behavior, such as only the first modal's data being logged.

To resolve this, you should create a separate modal instance for each modal element. Here's how you can modify your code to achieve this:

  1. Use a ref to store modal instances for each modal.
  2. Initialize the modal instance inside the onMounted lifecycle hook for each modal.

Here's an updated version of your script:

Key Changes:

  • Unique Modal IDs: Each modal now has a unique ID based on the list.id.
  • Separate Modal Instances: A ref object dialogInstances is used to store modal instances keyed by their unique IDs.
  • Dynamic Handling: The handleCancel and handleCreateCard functions now accept a modalId parameter to operate on the correct modal instance.

This setup ensures that each modal operates independently, and the correct data is logged and processed for each modal.

Please or to participate in this conversation.