quasarframework / quasar

Quasar Framework - Build high-performance VueJS user interfaces in record time
https://quasar.dev
MIT License
25.87k stars 3.51k forks source link

Dialog close() won't run if handler() is async #884

Closed TKafassis closed 7 years ago

TKafassis commented 7 years ago

I'm trying to use a async handler() to first send ajax with axios, await and then decide to close the dialog or not. It seems like close() is doing nothing in this case, is there some reason?

rstoenescu commented 7 years ago

Can you post your code? It's most likely a misusage somewhere. Thanks.

TKafassis commented 7 years ago

No idea why it doesn't format properly.

async handler(data, close) { let response = await axios.post('/api/dictionary', { entry: data.entry }) .then(response => response.data) .catch(error => error.response.data);

if (response.hasOwnProperty('errors')) {
    let errorFields = response.errors;

    let toastHtml = [];
    if (errorFields.hasOwnProperty('entry')) {
        for (let validationError of errorFields.entry) {
            toastHtml.push(validationError);
        }
    }

    Toast.create.negative({
        html: toastHtml.join('<br>')
    });
}
else {
    close(async() => {
        self.entries = await self.getEntries();

        Toast.create.positive({
            html: `Entry: ${data.oddsportal} - ${data.pinnacle} was saved successfully!`
        });
    });
}

}

TKafassis commented 7 years ago

I closed the issue because it worked at that time, but now it does nothing again. It seems to only work sometimes.

TKafassis commented 7 years ago

Switched to Modal, works great! Maybe I was trying to do a bit too much with Dialog.

jigarzon commented 7 years ago

I'm having the same problem. I even removed the entire aync part and the close handler seems to have a problem

jigarzon commented 7 years ago

This code is not closing the Dialog: (notice I commented the aync stuff and also removed any other buttons)

Dialog.create({
        title: this.$t('login.title'),
        form: {
          username: {
            type: 'text',
            label: this.$t('login.username'),
            model: ''
          },
          password: {
            type: 'password',
            label: this.$t('login.password'),
            model: ''
          }
        },
        buttons: [
          {
            label: this.$t('common.ok'),
            preventClose: true,
            handler(data, close) {
              close();
              //_this.login(data.username, data.password, close);
            }
          },
          //this.$t('common.cancel')
        ]
      })
jigarzon commented 7 years ago

My latest issue has been solved on 0.14.5. I think this issue can be closed