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

    q-dialog in async-await way?

    Framework
    3
    3
    1156
    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.
    • J
      jitendra16 last edited by

      How to use q-dialog as mixin function using async await?

          confirmation(title, msg) {
            this.$q.dialog({
              title: title,
              message: msg,
              ok: {
                push: true
              },
              cancel: {
                color: 'negative'
              },
              persistent: true
            }).onOk(() => {
              return true
            }).onOk(() => {
              return true
            }).onCancel(() => {
              return false
            })
          }
      
      1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman last edited by metalsadman

        Qdialog does not return a promise it did before in old version but for perf reason it’s dropped. What you could do is wrap it in a promise, then async await the returned promise accordingly.

        https://forum.quasar-framework.org/topic/3211/v1-q-dialog-now-returns-a-chainable-object-with-onok-oncancel-callbacks-not-a-promise-how-to-use-promise-with-it/4

        1 Reply Last reply Reply Quote 0
        • W
          walfin last edited by

          How I usually structure my code is

          if(await new Promise(resolve=>this.$q.dialog({
          ...
          cancel:true
          }).onOk(()=>resolve(true)).onCancel(()=>resolve(false)))){
          //ok code
          }else{
          //cancel code
          }
          

          In that sense the callbacks are more flexible than returning a Promise which calls catch() on cancel, as I would have to wrap my await call in a try block to handle the cancel button if such a Promise were returned (which to me looks more unwieldy than a simple if-else, I prefer using catch to handle real errors).

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