prevent closing modal on form submit
Is there a way to prevent the modal from closing when a form is submitted?
I'm working on a form presented to users via a simplemodal presented div.
// modal call $('#edit_container', document).modal( {onOpen: function (dialog) { dialog.overlay开发者_如何学Go.fadeIn('fast', function () { dialog.data.hide(); dialog.container.fadeIn('fast', function () { dialog.data.slideDown('fast'); }); }); } , onClose: function(dialog) { location.reload(true); $.modal.close(); } }); // simplemodal settings $.modal.defaults = { appendTo: 'body', focus: false, opacity: 70, overlayId: 'simplemodal-overlay', overlayCss: {}, containerId: 'simplemodal-container', containerCss: {}, dataId: 'simplemodal-data', dataCss: {}, minHeight: null, minWidth: null, maxHeight: null, maxWidth: null, autoResize: true, autoPosition: true, zIndex: 1000, close: true, closeHTML: '', closeClass: 'simplemodal-close', escClose: false, overlayClose: false, position: null, persist: true, modal: true, onOpen: null, onShow: null, onClose: null };
I have a jquery function that updates a table within the modal div:
// on submit function $('form#family-form').submit(function() { var condition = $('#edit-health',this).val(); $('>li> + condition + >/li>', document).appendTo('#health_edit_table td ul'); });
Any thoughts?
Thanks, Jonathan
If you actually want to submit the form then use ajax. If not then return false from your submit function.
// on submit function
$('form#family-form').submit(function() {
var frm = this;
$.ajax({
url:frm.attr('action'),
data:$(frm).serialize(),
success:function(data){
var condition = $('#edit-health',frm).val();
$('>li> + condition + >/li>', document).appendTo('#health_edit_table td ul');
}
});
return false;
});
Woops! I realized that this would need to be done via an AJAX or AHAH (drupal) call. Unless, anyone has a better idea.
精彩评论