I am using store.synch() method for post data. And validation done from server side, currently I am using message box for show error message. now I want to something different way to show error,but not markInvalid() because for this I have to change every js fiels and api also. so there is any alternative of markInvalid()?
what could be the best way to show error message in Extjs?
4.6k Views Asked by Naresh Tank At
2
There are 2 best solutions below
0

Hi Naresh Tank, my solution to your problem was to monitor all ajax request. This way you can send what error msg you want regardless this come from a store or an form.
I hope this help.
On the app.js
init: function() {
this.addAjaxErrorHandler(this);
},
addAjaxErrorHandler: function(object) {
Ext.Ajax.on('requestexception', function(conn, response, options, e) {
var statusCode = response.status,
errorText = null,
captionText = response.statusText;
if (statusCode === 0 || statusCode === 401) {
Ext.Ajax.abortAll();
}
if(response.statusText==="Authorization Required"){
Ext.Ajax.abortAll();
}
// 404 - file or method not found - special case
if (statusCode == 404) {
Ext.MessageBox.alert('Error 404', 'URL ' + response.request.options.url + ' not found');
return;
}
if (response.responseText !== undefined) {
var r = Ext.decode(response.responseText, true);
if (r !== null) {
errorText = r.ErrorMessage;
}
if (errorText === null)
errorText = response.responseText;
}
if (!captionText)
captionText = 'Error ' + statusCode;
Ext.MessageBox.alert(captionText, errorText);
},
object);
Ext.Ajax.on('requestcomplete', function(conn, response, options, e) {
var statusCode = response.status,
errorText = null,
captionText = response.statusText;
if (response.responseText !== undefined) {
var r = Ext.decode(response.responseText, true);
if (r !== null && r.success === false) {
try{
if(typeof r.data[0].idUsr !== 'undefined')
return;
}catch(e){}
errorText = r.msg;
if (errorText === null)
errorText = response.responseText;
if (!captionText)
captionText = 'Error ' + statusCode;
Ext.MessageBox.alert(captionText, errorText);
}
}
},
object);
};
Extjs data store is provided with listeners, one of the listeners is exception (works on ExtJs < 3.x)
Here is the code.
By the way I didn't get what is markInvalid()