开发者

Odd custom date format fails to set correct selected date

开发者 https://www.devze.com 2023-01-23 20:23 出处:网络
When using the jQuery UI (1.8.6) datepicker plugin and attempting to use one specific odd cus开发者_开发技巧tom date format the calender fails to set the selected date.The format that fails is ymmdd (

When using the jQuery UI (1.8.6) datepicker plugin and attempting to use one specific odd cus开发者_开发技巧tom date format the calender fails to set the selected date. The format that fails is ymmdd (new years eve 2010 would be 101231). The selected date is correctly set in the input, but the calendar fails to indicate the selected date.

When setting other formats, such as y-mmdd, yyyy-mm-dd, etc - everything is working as expected and the selected date is defaulted when opening the calendar. When setting the ymmdd format, the calendar opens with todays date as default.

I'm configuring the datepicker using:

$(function() { $(".dateField").datepicker( { dateFormat: 'ymmdd' } ) } );

Is this a bug in the plugin or am I doing something wrong?


Investigated the source code for parseDate and it contained an error that made the datepicker handle the dateformat "y" incorrectly. The look ahead result was never used in order to determine the number of year digits to parse.

I changed the code for the getNumber closure to read:

var isDoubled = lookAhead(match);
var size = (match == '@' ? 14 : (match == '!' ? 20 :
    (match == 'y' && isDoubled ? 4 : (match == 'o' ? 3 : 2))));

After the change, the "ymd" format works as well. Will file a bug and make a pull request to submit the change.

0

精彩评论

暂无评论...
验证码 换一张
取 消