quasar icon indicating copy to clipboard operation
quasar copied to clipboard

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

Open TKafassis opened this issue 9 years ago • 7 comments

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?

TKafassis avatar Sep 14 '17 08:09 TKafassis

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

rstoenescu avatar Sep 14 '17 08:09 rstoenescu

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 avatar Sep 14 '17 08:09 TKafassis

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

TKafassis avatar Sep 14 '17 09:09 TKafassis

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

TKafassis avatar Sep 14 '17 13:09 TKafassis

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

jigarzon avatar Oct 13 '17 21:10 jigarzon

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 avatar Oct 13 '17 21:10 jigarzon

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

jigarzon avatar Oct 14 '17 15:10 jigarzon