0

I need to create a single toast on the screen of my application, today if I click multiple times on a button, several toasts are presented.

EDIT:

showToast: function(message) {
    var openedToast = Ext.get(document.querySelector('[id^="toast-"]'));
    if (openedToast != null) {
        var toast = Ext.getCmp(openedToast.id);
        toast.close();
    }
    Ext.defer(function() {
        Ext.toast({
            html: message,
            align: 't'
        });
    }, 80);
}

But if the user clicks the button quickly, the toast is created several times

Roberto Pegoraro
  • 1,313
  • 2
  • 16
  • 31
  • Need way more specifics than this. Post some code, created a plunkr if possible, talk about what you've tried, what is the expected behavior, etc. โ€“ TomSlick Jun 08 '17 at 20:03
  • But what exactly you want to do with other toasts (If you want to display multiple toasts at once)? Just ignore or remove previous toast and show new one or...? โ€“ Sergey Novikov Jun 09 '17 at 15:18
  • I need to remove previous toast. See the edition โ€“ Roberto Pegoraro Jun 12 '17 at 12:16

1 Answers1

2

Just give it a unique identifier and check if it already exists before creating a new one.

{
    xtype: 'button',
    handler: function(){
        if(!Ext.ComponentQuery.query('#myToast').length){
            Ext.toast({
                itemId: 'myToast',
                html: 'toast!'
            });
        }
    }
}

ยป Fiddle

Emissary
  • 9,954
  • 8
  • 54
  • 65