EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: AJLX on March 02, 2017, 04:39:01 AM



Title: Date Time Box Add Year Button
Post by: AJLX on March 02, 2017, 04:39:01 AM
Hello Guys,

I want to add a button to the date box editor so that when I click on it, it selects the same date, but next year. So if today is
02/03/2017 when I click this button it returns 02/03/2018. It should be simple, but I'm totally new to Jquery. I come for a PHP background. I can understand you not wanting to give me the full answer, but could you help me with some advice on the steps I need to take.

Thanks,

Andy


Title: Re: Date Time Box Add Year Button
Post by: jarry on March 02, 2017, 08:10:07 AM
Please look at this code. It adds a new button 'NextYear' to the datebox.
Code:
$(function(){
$('#db').datebox({
buttons: (function(){
var buttons = $.extend([], $.fn.datebox.defaults.buttons);
buttons.splice(1, 0, {
text: 'NextYear',
handler: function(target){
var opts = $(target).datebox('options');
var c = $(target).datebox('calendar');
var date = c.calendar('options').current;
date.setFullYear(date.getFullYear()+1);
$(target).datebox('setValue',opts.formatter(date));
$(target).datebox('hidePanel');
}
});
return buttons;
})()
})
})


Title: Re: Date Time Box Add Year Button
Post by: AJLX on March 05, 2017, 10:49:58 AM
Thanks,

I've added that code into the body of the page, and it just adds a new date box. presumably I need to put it somewhere sensible!?