![](/img/trans.png)
[英]How to get keyCode at OnSelect event of Jquery DatePicker?
[英]jEditable - How to bypass the submit in datepicker onselect event
我正在將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事件嗎? 希望可以在這里得到一些幫助...謝謝....
嘗試這樣的事情:
plugin : function(settings, original) {
..
$(this).find('input').datepicker().bind('click', function(e) {
//e.preventDefault() // also test this
return false;
})
您能簡單地檢查所選日期是否有效,是否僅提交並形成表格?
onSelect: function(dateText, inst) {
if (/* dateText is valid */) {
form.submit();
}
}
我通過不停止提交來完成它,但是如果驗證失敗,則將輸入值改回默認值。 這是我能完成的唯一方法。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.