Calendar date rolling back to 1930's
I am using a custom Jquery code for Jquery Calendar date picker. For some reason when a date is a and user user want to edit it, the date now shows 1930's. Say I first picked 10 Dec 2028, when I come back to pick it to edit, it now show 10 Dec 1928. Below is my code. Any help will be appreciated.
- var format = 'd M y'; // Jquery 'd M y' must match .net 'd MMM yy' date format
- function clear_form_elements(ele) {
- $(ele).find(':input').each(function () {
- switch (this.type) {
- case 'datetime':
- case 'text':
- $(this).val("");
- break;
- case 'radio':
- this.checked = false;
- $('#dtSubmit').datepicker('setDate', null);
- $('#dtFinalSubmit').datepicker('setDate', null);
- }
- });
- }
- $(document).ready(function () {
- $('.cDatePicker').off("calendarLoad");
- $('.cDatePicker').on("calendarLoad", function () {
-
- var locale = 'en-US';
- $.datepicker.setDefaults($.datepicker.regional[locale]);
- $(this).datepicker({
- dateFormat: format,
- changeYear: true,
- changeMonth: true,
- defaultDate: 0 // Default calender to the current system date.
- });
- var initDate = $(this).val();
- var initSet = initDate != '';
- if (initSet) {
- var parsedDate = $.datepicker.parseDate(format, initDate);
- $(this).datepicker("setDate", parsedDate);
- $(this).datepicker("option", "defaultDate", parsedDate);
- }
- var minAttr = $(this).data('min');
- var minSet = typeof minAttr !== typeof undefined && minAttr !== false;
- if (minSet) {
- var minDateVal = new Date(minAttr);
- $(this).datepicker("option", "minDate", minDateVal);
- if (initSet == false) {
- $(this).datepicker("option", "defaultDate", minDateVal);
- }
- }
- var maxAttr = $(this).data('max');
- var maxSet = typeof maxAttr !== typeof undefined && maxAttr !== false;
- if (maxSet) {
- var maxDateVal = new Date(maxAttr);
- $(this).datepicker("option", "maxDate", maxDateVal);
- if (initSet == false && minSet == false) {
- $(this).datepicker("option", "defaultDate", maxDateVal);
- }
- }
- });
- $('.cDatePicker').trigger("calendarLoad");
- });
- // Override the date validation that to match date format.
- $(function () {
- $.validator.addMethod('date',
- function (value, element) {
- if (this.optional(element)) {
- return true;
- }
- var valid = true;
- try {
- $.datepicker.parseDate(format, value);
- }
- catch (err) {
- valid = false;
- }
- return valid;
- });
- $('.cDatePicker').datepicker({ dateFormat: format });
- });