This question has little to do with jQueryUI's dialog, and more to do with JavaScript.
I pass some variables to ayb.dialogError()
, and use them to create a dialog. Then I pass different values, but the first are still used.
The below script is condensed to highlight the issues, and the full script is located at https://jsbin.com/muhijodima.
Within the open
callback, how do I access the variables passed to ayb.dialogError()
?
$(function(){
ayb={};
ayb.dialogErrorElem=undefined;
ayb.dialogError=function(t,e) {
if (typeof ayb.dialogErrorElem === 'undefined') {
ayb.dialogErrorElem=$('<div/>').appendTo('body').dialog({
open: function(event, ui){
console.log('dialog.open',t,e);
//t=function(){return t;}
//e=function(){return e;}
},
});
console.log(ayb.dialogErrorElem);
};
ayb.dialogErrorElem.dialog('open');
}
$('#e1').click(function(){ayb.dialogError('Title1',['error1-1','error1-2'])});
$('#e2').click(function(){ayb.dialogError('Title2','error2-1')});
});
I expect this is not the best way to do so, however, the passed parameters are available to the open
callback.
Condensed script below to highlight concept, and full script at https://jsbin.com/segoxewape/edit?html,output.
If there is a better way to make the parameters available in the callback (which I am sure there is), please comment.
ayb.dialogError=function(t,e) {
getEm=function(){return {e:e,t:t};}
var v={e:e,t:t}; //Won't work
if (typeof this.dialog === 'undefined') {
this.dialog=$('<div/>', {})
.dialog({
open: function(event, ui){
console.log('Wrong values in dialog.open!',t,e,v.t,v.e);
var o=getEm();
console.log('Right values!',o);
}
});
};
this.dialog.dialog('open');
}