q.dialog async await in a function



  • 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


Log in to reply