No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Dialog Plugin with Promise

    Help
    3
    4
    818
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      snowdrop last edited by

      Good day, I’m currently playing with dialog plugin and seems good to me for just simple prompt. I’m wondering if the plugin can also return a Promise, as checking the documentation does not suggest so to take advantage of async-await function of javascript. It would be cool if it can be integrated as using callbacks sometimes reduces the readability of the code if you have a lot of branching in your code. Thanks!

      1 Reply Last reply Reply Quote 1
      • s.molinari
        s.molinari last edited by s.molinari

        You only put in callbacks (single functions) for the the chained methods or “options” given to you by the dialog’s returned object (onOk, onCancel, onDismiss) and only for those you need to use. Thus, the code won’t (or shouldn’t) get so complicated it becomes hard to read. Maybe I’m misunderstanding your needs, but it sounds like your possibly overcomplicating the plugin.

        If you need to do more with dialogs, you’re probably better off using the QDialog component.

        Scott

        1 Reply Last reply Reply Quote 1
        • S
          snowdrop last edited by

          @s-molinari Yes, I’ve resorted to QDialog component as Dialog plugin is not sufficient for my implementation. Thank you for your response. 🙂

          1 Reply Last reply Reply Quote 1
          • J
            jraez last edited by

            One thing that can help is to create global Vue mixin in boot file.
            https://quasar.dev/quasar-cli/cli-documentation/boot-files

            export default async ({ Vue }) => {
              // Inject quasar extension into the vue
              Vue.mixin({
                methods: {
                  dialog (options) {
                    return new Promise((resolve, reject) => {
                      this.$q.dialog(options).onOk(() => {
                        resolve()
                      }).onCancel(() => {
                        reject()
                      })
                    })
                  }
                }
              })
            }
            

            This way, in any component you have dialog method available that is a promise. you can async-await for. I think you have to tune it to suit your need but it can be a good start.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post