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

Events not working on Dynamic Dialog #7284

Closed
1 of 4 tasks
lukas-pierce opened this issue Feb 20, 2025 · 2 comments
Closed
1 of 4 tasks

Events not working on Dynamic Dialog #7284

lukas-pierce opened this issue Feb 20, 2025 · 2 comments
Assignees
Labels
Component: Documentation Issue or pull request is related to Documentation
Milestone

Comments

@lukas-pierce
Copy link

Describe the bug

I am trying to send events from a dynamic dialog as shown in the example in your documentation:
https://primevue.org/dynamicdialog/#events

However, this does not work. Maybe I'm doing something wrong?

index.vue

<template>
  <div>
    <h1>Example Page</h1>
    <Button label="Open Dynamic Dialog" @click="openDialog" />
  </div>
</template>

<script setup lang="ts">
import ExampleDialog from '~/components/ExampleDialog.vue';

const dialog = useDialog();
const openDialog = () => {
  dialog.open(ExampleDialog, {
    props: {
      header: 'Example Dialog',
      modal: true,
    },
    onSaved: () => {
      alert('saved'); // ----------- Not called
    },
  });
};
</script>

ExampleDialog.vue

<template>
  <div>
    <p>Test stackblitz alert works</p>
    <Button label="Test alert" @click="testAlert" />
    <br />
    <br />

    <p>Ok, lets try emit 'saved' event from dynamic dialog</p>
    <Button label="Save" @click="save" />
  </div>
</template>

<script setup lang="ts">
const emit = defineEmits(['saved']);

const testAlert = () => {
  alert('Its works!');
};

const save = () => {
  emit('saved');
};
</script>

Pull Request Link

No response

Reason for not contributing a PR

  • Lack of time
  • Unsure how to implement the fix/feature
  • Difficulty understanding the codebase
  • Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/nuxt-starter-mecvw6bm?file=pages%2Findex.vue,components%2FExampleDialog.vue

Environment

macOS Sequoia, Google Chrome

The problem reproducible in stackblitz

Vue version

3.5.13

PrimeVue version

4.2.5

Node version

v18.19.0

Browser(s)

No response

Steps to reproduce the behavior

  1. Open stackblitz link https://stackblitz.com/edit/nuxt-starter-mecvw6bm?file=pages%2Findex.vue,components%2FExampleDialog.vue
  2. Open index.vue page
  3. Click "Open Dynamic Dialog" button
  4. Press "Save" button in the dialog

Expected behavior

I expected the event to be passed to the page and an alert to occur. But this does not happen.

@lukas-pierce lukas-pierce added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 20, 2025
@YannisJustine
Copy link
Contributor

You need to add emits object.
It's written in the documentation but the example isn't updated:

The emits object defines callbacks to handle events emitted by the component within the Dialog.

Example

<template>
  <div>
    <h1>Example Page</h1>
    <Button label="Open Dynamic Dialog" @click="openDialog" />
  </div>
</template>

<script setup lang="ts">
import ExampleDialog from '~/components/ExampleDialog.vue';

const dialog = useDialog();
const openDialog = () => {
  dialog.open(ExampleDialog, {
    props: {
      header: 'Example Dialog',
      modal: true,
    },
    emits: {
      onSaved: () => {
        alert('saved'); 
      }
    }
  });
};
</script>

@tugcekucukoglu
Copy link
Member

Thanks for the updates. The documentation will be updated.

@tugcekucukoglu tugcekucukoglu added Component: Documentation Issue or pull request is related to Documentation and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 21, 2025
@tugcekucukoglu tugcekucukoglu added this to the 4.3.0 milestone Feb 21, 2025
@tugcekucukoglu tugcekucukoglu self-assigned this Feb 21, 2025
@github-project-automation github-project-automation bot moved this to Review in PrimeVue Feb 21, 2025
@github-project-automation github-project-automation bot moved this from Review to Done in PrimeVue Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Issue or pull request is related to Documentation
Projects
Status: Done
Development

No branches or pull requests

3 participants