Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Modals #46

Open
trondhuso opened this issue Sep 23, 2022 · 1 comment
Open

Multiple Modals #46

trondhuso opened this issue Sep 23, 2022 · 1 comment

Comments

@trondhuso
Copy link

has anyone tried to implement multiple modals? I am currently trying to, but it shows the same modal even though it has a different value under x-show

any pointers welcome

@itsDevKay
Copy link

itsDevKay commented Jan 26, 2023

Are you sharing the same @click function? I had to create a new function in init-alpine.js in order to make it work with multiple modals.

// Default Modal
    isModalOpen: false,
    trapCleanup: null,
    openModal() {
      this.isModalOpen = true
      this.trapCleanup = focusTrap(document.querySelector('#modal'))
    },
    closeModal() {
      this.isModalOpen = false
      this.trapCleanup()
    },

   // my added modal
    isConfirmDeleteModalOpen: false,
    openConfirmDeleteModal(e) {
        this.isConfirmDeleteModalOpen = true
        this.trapCleanup = focusTrap(document.querySelector('#confirm-delete-modal'))
        document.querySelector('#confirm-delete-button').setAttribute(
            'data-event-uuid',
            e.target.getAttribute('data-event-uuid')
        )
        document.querySelector('#confirm-delete-for-title').textContent = (
            e.target.getAttribute('data-event-title')
        )
    },
    closeConfirmDeleteModal() {
        this.isConfirmDeleteModalOpen = false
        this.trapCleanup()
        document.querySelector('#confirm-delete-button').setAttribute(
            'data-event-uuid', ''
        )
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants