Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notify.js clear old notifications

I'm using Notify.js to show notifications on my site. I encountered a problem, where I add notifications show them and then, if I want to show different notification and add it as well, I see the old notifications as well. The work flow is:

  1. User input data
  2. User press a button
  3. Data is validated
  4. Error notification added
  5. Goes on until everything is correct

In order to add a notification I use the following:

var noteOption = {
    // whether to hide the notification on click
    clickToHide : true,
    // whether to auto-hide the notification
    autoHide : false,
    globalPosition : 'bottom right',
    // default style
    style : 'bootstrap',
    // default class (string or [string])
    className : 'error',
    // show animation
    showAnimation : 'slideDown',
    // show animation duration
    showDuration : 400,
    // hide animation
    hideAnimation : 'slideUp',
    // hide animation duration
    hideDuration : 200,
    // padding between element and notification
    gap : 10
}
var note = "My Error Message"
$.notify.defaults(noteOption);
$.notify(note, "error");

So now the actual question, how do I clear the notifications before adding new ones?

Thanks,
Liron

like image 986
Liron Avatar asked Oct 27 '25 10:10

Liron


2 Answers

This is because the function you call always return a new instance of Notification The best way is clear the old notification container:

$('.notifyjs-corner').empty();

Regretly they don't have function like: $.singletonNotify()

like image 149
ThangTD Avatar answered Oct 30 '25 01:10

ThangTD


This worked for me:

$.notifyClose();
$.notify({...});

https://github.com/mouse0270/bootstrap-notify/issues/136#issuecomment-204051563

like image 40
Vidya Avatar answered Oct 30 '25 01:10

Vidya