jquery ui datepicker back button jumps to 1899

血红的双手。 提交于 2019-12-04 04:51:37

I had this issue when I had multiple text inputs with the same ID, which is easy to do with MVC frameworks when you have multiple editors on page for same model class. I resolved it by explicitly specifying Id and leaving Name as is, so that model resolving works on postback.

This was caused by having multiple input fields with the same id, in my current project.

I was generating multiple forms at the front end, with the same creation method in my framework.

To avoid having to write explicit changes at the form creation level, I did the following:

//An initialisation method for datepickers
var init_datepickers = function() {
  /* Datepickers */
  $('.datepicker').datepicker({
    dateFormat: "dd/mm/yy" //(I'm in NZ)
  });
}
//Define counter ("datepicker index" aka dpi)
var dpi = 0;
//Loop datepickers
$.each($('input.datepicker'), function() {
  if(dpi > 0)
    $(this).attr("id", $(this).attr("id") + "_" + dpi); //Append the current count to the ID
  dpi++;
  //Check for last datepicker, and call init
  if(dpi == $('input.datepicker').length)
    init_datepickers();
});

This ads a number to all datepickers, other than the first one that appears on the page.

Note: This example doesn't really call for the use of ID's as selectors for scripts or styling. This will change the ID's of the inputs, and therefor, will break any styling / selection that you may have.

I experienced this issue when calling

$(...).datepicker('destroy')

before re-initializing the datepicker.

Blaaa

It happens when if you have a default instance, because in jQuery plugin its configured that default date is 1899.

We have to just find out why this when this default date code fires

I have created a demo with your code in jsfiddle and I can't reproduce your problem. Can you check it at http://jsfiddle.net/w78xX/.

I have same issue. I'm populating datepicker fields with ajax and showing them on PrettyPhoto as popup.

Here is my code.

$( "body" ).on( "focus", ".tarih", function() {
    //$('.tarih').datepicker('destroy');
    var i = 0;
    $('.tarih').each(function () {
        //$(this).attr("id",'date' + i).datepicker('destroy');
        $(this).attr("id",'date' + i).datepicker({
            dateFormat: "yy-mm-dd",
            firstDay: 1,
            minDate: new Date(2000, 1 - 1, 1)
        });
        i++;
    });
});

Try using: format: 'mm/dd/yyyy hh:ii:ss P' The trick is to keeping your date format the same as what the back-end returns.

I had the same issue and adding the useCurrent: false resolves it.

.datepicker({
        useCurrent: false 

    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!