我有一个表单,我希望用户在尝试提交时确认其中一个值,并且我希望在 jQuery UI 模式对话框中进行确认。
代码看起来像这样:
valuesCheck = function(event) {
$j("#proposal-form-errors")
.dialog({
modal: true,
width: 600,
title: 'Values Confirmation',
buttons: {
"Confirm values and submit proposal": function () {
$form = $j('form#proposal');
$form.addClass('values-confirmed');
$j(this).dialog("destroy");
$form.submit();
},
"Continue editing": function () {
$j(this).dialog("destroy");
}
}
})
.html('<p>Please confirm the selected values.</p>');
event.preventDefault();
}
$j("form#proposal").submit(function(event) {
var val1 = $j("#val1 option:selected").text();
var val2 = $j("#val2").val();
if (val1 && val2 && !$j(this).hasClass('values-confirmed')) {
valuesCheck(event);
} else {
return true; // processing stops here after the first click.
}
});
通过在 Firebug 中设置断点,我可以看到一切正常,除了在单击“确认值并提交提案”后,当它通过提交函数中的“返回 true”行时,没有任何反应。如果我再次触发提交事件,表单将实际提交。
我认为问题与“event.preventDefault()”有关,但没有它,模式对话框会消失,并且在确认之前提交表单。
我也尝试$form.submit()
从valuesCheck
处理程序中再次调用该方法,但无济于事。
如何使模式对话框中的“确认值并提交提案”按钮在单击时实际提交表单?