I have a simple_dialog displaying information from a form in a custom module. I would like to be able to programmatically close the dialog in response to a click event on certain links within the dialog. However, I am unable to cause the dialog to close.
Here is a code excerpt. This code is executed as a result of an "onclick" attribute.
function sponsorLookupSelect(id) {
jQuery.ajax({
dataType: "json",
url: '/sponsor-lookup/member-info?userId=' + id,
success: function(data){
var nameField = '#edit-field-sponsor-name-und-0-value';
var emailField = '#edit-field-sponsor-e-mail-und-0-email';
// Set the sponsor name and email in the correct sponsor fields.
// These are working.
jQuery(nameField).val(data.name);
jQuery(emailField).val(data.email);
// This part is not working.
jQuery('#simple-dialog-container').dialog('close');
}
});
}
What am I doing wrong?
Thanks!
Comments
Comment #1
drclaw commentedHmm... I just tested closing a dialog programmatically and it should work with
jQuery('#simple-dialog-container').dialog('close');. Are you getting any kind of error output?Comment #2
paulmckibbenThanks for the quick response and for trying it out. Unfortunately, I'm not getting any error output. I'm not even able to get Firebug to stop at a breakpoint within that ajax callback. Could the fact that it is within an ajax callback have something to do with the problem?
Comment #3
pico34 commentedI have the same problem I can not close the window properly.
I tried this:
This seems to work because the window disappears, but I can not open it again.
I hope to find a solution ...
Comment #4
pico34 commentedThe good way is :
jQuery('.ui-icon-closethick').trigger('click');cf. http://drupal.stackexchange.com/questions/64897/how-do-i-programmaticall...
Yeah :)
Comment #5
drclaw commented@paulmckibben: Is your AJAX callback doing any of the other stuff in it? (e.g.
jQuery(nameField).val(data.name);)Comment #6
paulmckibbenYes, the other code in the callback is being executed (e.g. jQuery(nameField).val(data.name);). The nameField is in the main portion of the page, and not within the simpleDialog.
Comment #7.0
(not verified) commentedminor fix to code example
Comment #8
philsward commentedExample of my code to accomplish this:
Or, if you prefer an anchor link: