At the same time, I also recently created a new function that allows validating fields with the jqueryui dialog.
Very easy to use
dlgConfirm('Are you sure you want to cancel this change-email request? <br><label>Current password<br><input type="password"></label>', 'Cancel Email Change', 'Continue', function(dlg){ //do ajax or something return false; //do not close dialog until ajax is complete } dlgConfirm('Are you sure you want to submit this form', function(dlg){ $('form', dlg).submit(); return true; });
Here is the source code (public domain):
<script> function dlgConfirm(c_text, c_title, c_btn_text, c_btn_cancel_text, confirm_callback){ if (typeof(confirm_callback) !== 'function'){ if (typeof(c_title) == 'function'){ confirm_callback = c_title; }else if (typeof(c_btn_text) == 'function'){ confirm_callback = c_btn_text; }else if (typeof(c_btn_cancel_text) == 'function'){ confirm_callback = c_btn_cancel_text; } } if (typeof(c_text) !== 'string'){ c_text = 'Are you sure?'; } if (typeof(c_title) !== 'string'){ c_title = 'Confirm'; } if (typeof(c_btn_text) !== 'string'){ c_btn_text = 'Confirm'; } if (typeof(c_btn_cancel_text) !== 'string'){ c_btn_cancel_text = 'Cancel'; } if ($('#dlgConfirm').length == 0){ $('body').append('<div id="dlgConfirm" title="Confirm" style="display: none">Are you sure?</div>'); } var btns = {}; btns[c_btn_text] = function() { var dlg = this; if (typeof(confirm_callback) == 'function'){ if (confirm_callback(dlg) !== false){ $(this).dialog('close'); } } }; btns[c_btn_cancel_text] = function() { $( this ).dialog("close"); }; $('#dlgConfirm').dialog({ title: c_title, autoOpen: false, resizable: false, </script>
source share