DateTimePicker icon indicating copy to clipboard operation
DateTimePicker copied to clipboard

Set default date when clicking on a text field

Open kylex opened this issue 8 years ago • 9 comments

Here is my html: <div data-field="date">Choose Date</div>

Here is my js:

$("#dtBox").DateTimePicker({
  dateFormat: "yyyy-MM-dd",
  titleContentDate: '',
  buttonsToDisplay: ["SetButton"],
  animationDuration: 100,
  beforeShow: function(oInputElement)
  {
     var oDTP = this;
     oDTP.settings.defaultDate = new Date();
  }
});

Unfortunately I just get NaN in the datepicker pop-up. How can I force the initial view to be the current date, given a random text div?

kylex avatar Dec 03 '15 06:12 kylex

Sorry, you can not achieve this with DateTimePicker.

nehakadam avatar Dec 03 '15 06:12 nehakadam

I've added this code to line 1957 in order to default to the current date when a non date object is submitted:

if (Object.prototype.toString.call(oDTP.oData.dCurrentDate) === '[object Date]' && isFinite(oDTP.oData.dCurrentDate)) 
{
    dTemp = new Date(oDTP.oData.dCurrentDate);
}
else {
    dTemp = new Date();
}

This works, but I'm not familiar enough with your code to know if there's a better way to do this.

kylex avatar Dec 03 '15 06:12 kylex

:+1: It is correct. But I will need to check everything so will update library later.

nehakadam avatar Dec 03 '15 07:12 nehakadam

Made a pull request with this change, and another to set off a "TAB" button identifier for callbacks. Basically, since Tab can Set the date, there are cases in callbacks where we need to know when Tab has set and closed the datepicker.

kylex avatar Dec 04 '15 05:12 kylex

Thanks. I will merge PR later. There are other PRs in a queue to be merged.

nehakadam avatar Dec 04 '15 06:12 nehakadam

I have merges PR but there was one error in buttonClicked functionality. So use latest version in which I fixed a bug.

nehakadam avatar Dec 05 '15 05:12 nehakadam

Shouldn't the following be outside of the if(bFromTab)?

    if(oDTP.settings.buttonClicked)
        oDTP.settings.buttonClicked.call(oDTP, "TAB", oDTP.oData.oInputElement);

Otherwise it only fires if you shift+tab and not when you tab forward. Tabbing forward makes bFromTab return false...

kylex avatar Dec 06 '15 03:12 kylex

I am able to navigate using TAB Forward. There may a cross browser issue. I have tested on Chrome, Safari, Firefox and Opera on Mac.

In which browser SHIFT+TAB is is working? actually it should hide picker. In all the browsers above it is hiding Picker as per condition written on line 1417, when Picker is open. Only when Picker is hidden SHIFT+TAB shows it.

nehakadam avatar Dec 07 '15 05:12 nehakadam

That's good! I think it is more better if DateTimePicker can add DateTimePicker({option : opts}) to update options.

Emiya0306 avatar Apr 27 '16 07:04 Emiya0306