it is a very simple question that I'm not finding an answer for it. I have a dialog and in some events happening inside the dialog I want to click one of the dialog buttons. The code which defines the dialog is:
var dialog = $('<div>').dialog({
autoOpen: false,
title : title,
resizable : false,
buttons : {
'CANCEL' : {
text : messages.Cancel,
click : function(){$(this).dialog('close')}
},
'OK' : {
text : messages.Ok,
click : okButtonCallback
}
}
});
and in my event I can get the dialog, find the buttons but I can not trigger the click event with right reference passed as this. I do this:
buttons = dialog.dialog('option', 'buttons');
and I have the buttons each of them has the click function. If called directly or through trigger('click'), they call the click event of button but with the button itself as this not the dialog object. I saw somewhere to call
buttons['OK'].apply(dialog);
but my buttons have absolutely no apply function!
I'm not sure what can I do!
First of all, you need to get buttons[0]
not buttons['OK']
, then, it's not a function it's an object, try to get to click function like this :
buttons[0].click.apply(dialog);
$('.ui-button:contains("Ok")').click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With