[英]x-editable datepicker Year/ Month only
I have modified the jQuery UI datepicker to only display year and month. 我已将jQuery UI datepicker修改为仅显示年份和月份。 I have used these javascript events to handle the data: http://jsfiddle.net/2puz2/4/
我使用这些javascript事件来处理数据: http : //jsfiddle.net/2puz2/4/
$( "#datepicker" ).datepicker({
showButtonPanel: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm',
currentText: 'This Month',
onClose: function(dateText, inst) {
var month = $('#ui-datepicker-div .ui-datepicker-month :selected').val();
var year = $('#ui-datepicker-div .ui-datepicker-year :selected').val();
$(this).datepicker('setDate', new Date(year, month, 1));
var setMonth = ('0' + (parseInt(month) + 1)).slice(-2);
$(this).val('Start: ' + year + '-' + setMonth);
},
beforeShow: function(input, inst) {
if ((datestr = $(this).val()).length > 0) {
var dateOutOfDesc = datestr.match(/\d{4}\-\d{2}/);
var dateparts = dateOutOfDesc[0].split('-');
var year = dateparts[0];
var month = dateparts[1];
$(this).datepicker('option', 'defaultDate', new Date(year, month-1, 1));
$(this).datepicker('setDate', new Date(year, month-1, 1));
}
}
});
Now I would like to use x-editable to edit this date, but I cannot figure out how to attach these callback functions to the builtin datepicker. 现在我想使用x-editable来编辑这个日期,但我无法弄清楚如何将这些回调函数附加到内置的datepicker。 I've tried
我试过了
editable.input.options.datepicker.beforeShow = function(input, inst) {
...
See this http://jsfiddle.net/L2Z9Q/18/ 见http://jsfiddle.net/L2Z9Q/18/
But it seems like this is after the datepicker has already been initialised. 但似乎这是在datepicker已经初始化之后。
Any ideas? 有任何想法吗?
You should use the onChangeMonthYear
event (fired when month or year is changed - docs ) to update the datepicker date instead of onClose
. 您应该使用
onChangeMonthYear
事件(在月份或年份更改时触发 - 文档 )来更新datepicker日期而不是onClose
。 I don't have an explanation why the onClose
isn't fired... 我没有解释为什么
onClose
没有被解雇...
$('#yearmonth').editable({
pk: 1,
format: 'yyyy-mm',
viewformat: 'yyyy-mm',
datepicker: {
onChangeMonthYear: function( year, month, inst){
$(this).datepicker('setDate', new Date(year, month-1, 1));
}
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.