Skip to content

Instantly share code, notes, and snippets.

@dubgeiser
Created June 28, 2012 10:48
Show Gist options
  • Select an option

  • Save dubgeiser/3010641 to your computer and use it in GitHub Desktop.

Select an option

Save dubgeiser/3010641 to your computer and use it in GitHub Desktop.
jQuery dialog() and form fields.
//
// Situation: you have form, when a user clicks on something, a dialog needs to
// appear where the user can fill in some optional field of that form and in
// that dialog (s)he can click to submit the form.
//
// Possible solution: You hide the optional field, create a dialog via jQuery's
// dialog() and add a dialog button that submits the form.
//
// Problem: While the form submits, there is no optional field in the submitted
// data.
//
// What happened:
// When creating a jQuery dialog for a specific form field, jQuery moves that
// dialog out of the form element, so you need to put it back in, or it will not
// be in the submitted form values ($_POST, $_GET).
// This can be done by appending via appendTo().
//
// So, assuming you create a dialog on element #denyDossierNote in a form #edit
// you'd do something like:
//
$('#denyDossierNote').dialog(
{
autoOpen: false,
modal: true,
resizable: false,
overlay: true,
width: 318,
buttons:
{
'{$lblSend|ucfirst}': function()
{
$('#denyDossierNote').dialog('close');
$('form#edit').submit();
}
}
}).parent().appendTo($('form#edit'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment