Reputation: 751
Use toastr.js in my application, and I have such flow, when user submit form, I need to show toast and give him some time to close this toast by click close button to prevent sending data to the server, but if he do not close toast, data should be sent.
I have such problem:
toastr.options = {
closeButton: true,
onHidden: () => { //send data to the server },
onCloseClick: () => { console.log('you clicked close button') },
}
toastr.success('success');
And the problem is that onHidden method will always fired. Please help!
Upvotes: 2
Views: 4460
Reputation: 751
Good people help me! Solution is:
isPrevented = false;
toastr.options = {
closeButton: true,
onHidden: () => {
if (isPrevented) {
return false;
} else {
//Sent result to server;
}
},
onCloseClick: () => {
isPrevented = true
}
}
Thanks for all contributors! )
Upvotes: 1