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 async await in a function

    Framework
    1
    1
    299
    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.
    • H
      happymax last edited by

      Hi all,
      I have created a simple function to show a dialog that I use into some methods.

      The function that is before the “export default” section is this

      async function ConfirmDialog(title, msg) {
         if (await new Promise(resolve => this.$q.dialog({
           title: title,
           message: msg,
           ok: {
                 push: true,
                 label: 'Yes',
                 tabindex: 0
               },
           cancel: {
               push: true,
               label: 'No',
               tabindex: 1
             },
           persistent: true,
           focus: 'cancel'
         }).onOk(() => resolve(true)).onCancel(() => resolve(false)))) {
           return true
        } else {
          return false
        }
      }
      

      If I call this function inside a method, the fuction isn’t executed and the dialog isn’t show (with or without async await parameter).

      methods: {
      
       async ValidateOrder () {
                 this.descrerror = []
      
                if (!(cntrDate .getDay() % 6)) {
                                if  (await !ConfirmDialog('Confim', 'You have used a weekend day. Proceed ?')) {
                                    this.descrerror.push('You have used a weekend day.')
                                }
          }
      

      If I insert the code of the function inside the method all works fine

      methods: {
      
       async ValidateOrder () {
                 this.descrerror = []
               if (!(cntrDate .getDay() % 6)) {
                     if (await new Promise(resolve => this.$q.dialog({
                                  title: 'Confirm',
                                   message: 'You have used a weekend day. Proceed ?'',
                                   ok: {
                                         push: true,
                                         label: 'Yes',
                                         tabindex: 0
                                       },
                                   cancel: {
                                       push: true,
                                       label: 'No',
                                       tabindex: 1
                                     },
                                   persistent: true,
                                   focus: 'cancel'
                                 }).onOk(() => resolve(true)).onCancel(() => resolve(false)))) {
      
                                 } else {
                                  this.descrerror.push('You have used a weekend day. ')
                                 }
                  }
          }
      

      Does anyone have a suggestion to correctly display the message in the ConfirmDialog function?

      Thanks

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