【发布时间】:2011-10-19 12:37:07
【问题描述】:
我正在将 jeditable 与 datepicker 一起使用,并且我希望在用户选择日期后再将其提交到数据库后进行一些验证。我浏览了 jeditable-datepicker.js 并意识到一旦发生 onselect 事件就会触发提交。如何在事件中包含条件,使无效日期不会提交到数据库?
这是我使用 onsubmit 事件的试验:
$('.expirydatepicker').editable('@(Url.Action("Edit", "Stock"))',
{
type: 'datepicker',
indicator: 'saving...',
event: 'dblclick',
tooltip: 'Double click to edit...',
style: 'inherit',
width: ($('.datepicker').width() - 10) + "px",
onsubmit: function (settings, td) {
var tid = $(td).attr('id');
//alert(tid);
$.ajax({
async: false,
url: '/Stock/CompareDate',
type: 'GET',
data: { id: tid },
success: function (result) {
if (result < 0) {
alert("Expiry dare cannot be earlier than storage date");
return onSelect(false);
}
else {
return true;
}
}
});
}
});
jEditable-datepicker 函数:
/* attach jquery.ui.datepicker to the input element */
plugin: function( settings, original ) {
var form = this,
input = form.find( "input" );
// Don't cancel inline editing onblur to allow clicking datepicker
settings.onblur = 'nothing';
datepicker = {
dateFormat: 'D, dd M yy',
onSelect: function() {
// clicking specific day in the calendar should
// submit the form and close the input field
form.submit();
},
我想知道如果输入无效,我是否可以“停止” onselect 事件? 希望能在这里得到一些帮助...谢谢....
【问题讨论】:
标签: javascript jquery datepicker jeditable