Bacteria
Bacteria

Reputation: 8616

Why only one alert message is displaying when I am using Ext.Msg object?

In my ExtJs application I have created two alert message using Ext.Msg object along with the one normal java script alert. Below is code.

Ext.onReady(function(){
    Ext.Msg.alert("Alert One");
    Ext.Msg.alert("Alert Two");
    alert("Alert Three");
});

After running this code I found browser first displaying the normal alert message then the 2nd Ext JS alert message. It is not populating the 1st Ext JS alert message

So my questions are

  1. Why it is populating the normal java script alert first?
  2. Why it is not populating the 1st Ext JS alert message?

Am I doing something wrong? If not then why this is happening? Please help me.

Upvotes: 1

Views: 1052

Answers (2)

mindparse
mindparse

Reputation: 7295

Ext.MessageBox Is a singleton, therefore you cannot create multiple separate instances. To demonstrate this If you were to add a delay to showing the second one by say 5 seconds you would see the first one appear. E.g.

Ext.Function.defer(function(){
    Ext.MessageBox.alert("message two");
}, 5000);

Upvotes: 0

dfsq
dfsq

Reputation: 193301

The Ext.Msg.alert method does not stop javascript code from executing. It means that after the first Ext.Msg.alert has shown script execution carries on, opening the second Ext alert. According to how it works only one instance of alert message can be presented at a time, so the second one simply overwrites the first one.

As far as native alert function is concerned, it works totally different. It blocks UI and stops subsequent script execution. You can see it because it is rendered over any other page layout. That's why even though Ext alert is presented native browser alert will still cover it.

Upvotes: 2

Related Questions