DateTimePicker
DateTimePicker copied to clipboard
Set default date when clicking on a text field
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?
Sorry, you can not achieve this with DateTimePicker.
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.
:+1: It is correct. But I will need to check everything so will update library later.
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.
Thanks. I will merge PR later. There are other PRs in a queue to be merged.
I have merges PR but there was one error in buttonClicked
functionality. So use latest version in which I fixed a bug.
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...
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.
That's good! I think it is more better if DateTimePicker can add DateTimePicker({option : opts}) to update options.