f3oall / awesome-notifications

Lightweight JavaScript Notifications Library
https://f3oall.github.io/awesome-notifications/
MIT License
292 stars 40 forks source link

Dismiss Notification #14

Closed movepixels closed 5 years ago

movepixels commented 5 years ago

Is there a method to dismiss the notification other than clicking on it? For example if user submits a form and it has 1 error a notification saying "error please fix this field " and quickly corrects that error before the notification is dismissed I would want to close / remove it automatically since errors = 0 / null.

Real world example. Please enter a valid email notification appears, users corrects the email / now valid before the notification times out the user still can see the notification even if its fixed.

If there was a method to $awn.close() / $awn.closeAlert() / $awn.closeAll() something along those line?

Thanks,

Dave

f3oall commented 5 years ago

Hey, currently there's no option for this. We definitely can't provide an opportunity to close notifications on some events, because it will require some kind of internal custom event listeners. There's no function to close one or many notifications also.

If you need to hide notification somehow, save return value of method you use to show it. This return value is HTMLElement. After you save it, run your custom logic and then remove toast from DOM using saved value if necessary.

I created an issue related to your question. Watch it for further enhancements: https://github.com/f3oall/awesome-notifications/issues/15