0
我有一些datePickers
我定製的,這些讓他們只顯示年份和月份
這是代碼來創建它們的jQuery插件驗證對自定義jQueryUI的datePickers
jQuery("input[name*='fechauso']").each(function() {
jQuery(this).datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
constrainInput: true,
showOn: 'button',
buttonText: 'Seleccionar...',
onClose: function(dateText, inst) {
var month = jQuery("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = jQuery("#ui-datepicker-div .ui-datepicker-year :selected").val();
jQuery(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
現在,我已經加了自定義驗證方法(使用插件)檢查此:
- 如果用戶沒有選擇使用按鈕的日期,字段爲空,所以自定義驗證器方法應該觸發。這不會發生。
這裏是定製validate方法
jQuery.validator.addMethod("isEmpty", function(value, element) {
return (value == '');
}, "Must select a date with the button besides control");
jQuery("#ct_2_fechauso").rules("add", {
required: "#campotilde_psico:checked",
isEmpty: true
});
的問題是,即使我選擇一個日期,它總是讓我重新選擇一個日期。日期選擇字段應該是隻讀