Reputation: 707
I'm working on a project with Extjs, version 4.0.7 and i have a problem. I have a function which verifies data validity before save. It looks like this:
me.validateEmployeeSystemSettingsOnSave = function (a,b,c) {
switch (c) {
case 1:{
if(expression)
return {success: false}
if(expression2){
Ext.Msg.show({
title:'',
msg:'',
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.QUESTION,
fn: function (btn) {
if (btn == 'yes') {
return { success: true };
}
else if (btn == 'no') {
return { success: false};
}
},
modal: true
});
}
else return {success: true}; /*problem line*/ //this is the default answer, when function will
//not enter any expression and return {success: true}
}
case 2:{
}
}
My above function is called in an onSave function like this:
var response = me.validateEmployeeSystemSettingsOnSave(dsa,ssa,daa){
if(response.success){
this.save();
}
else{
}
}
My question is:
Is there any way to wait for the answer of the Ext.msg.show(), before reaching the default return
, which i marked with /problem line/ ?
Because now the function doesn't take my yes or no answer, it always return {success: 'true'}
, which is normal, taking into consideration how is the function structured.
Any ideas? Thank you!
Upvotes: 1
Views: 4191
Reputation: 23975
You should never wait, Use a callback instead! So in your case execute a callback instead of returning { success: true };
Upvotes: 3