When i set minDate in any way weather by in options when initialising or weather like this
$(element).data('DateTimePicker').minDate(date);
In both the ways the date is printed in the text box i just want to use it to set that user can't select the date previous then the initialised date but it should not print that in the text box.
Error for me because i am using two boxes for start date and end date and i am initialising same date in both text boxes suppose 1st August 2016 so that user can't select date before 1st August 2016 in both boxes but i don't want it to print it.
I am using version 4.17.37
I noticed this issue as well, but I also discovered that the changing of the value also triggers the dp.change event too so that if you have any listeners. This causes problems when having a 'to' and 'from' date.
So if you have the 'to' minDate being set to the current date/time of the 'from' and the 'from' maxDate being set to the current date/time of the 'to', you'll find that you can't change the dates after the first change of the dates.
I've got a work around for you
var dateChangeTrigger, newDate
dateChangeTrigger = false;
//Create a control var and set to false
$(element).on('dp.change',function(e){
//Lister for event
newDay = new Date(e.date._d)
//get the newly updated date/time
if(dateChangeTrigger){
//Now check if the listen event has previously fired, if so reset back to false but don't do anything else
dateChangeTrigger=false
}else{
//Since this is the first time the change has been picked up, then trigger the appropriate action depending on if it's the from or to date/time
if(e.target.id=='TimeFrom'){
dateChangeTrigger=true
//Make sure to update the control var first since once the min/maxDate is triggered it causes a small recursion so never updates any values below
$('#TimeTo').data("DateTimePicker").minDate(newDay)
}else if(e.target.id=='TimeTo'){
dateChangeTrigger=true
$('#TimeFrom').data("DateTimePicker").maxDate(newDay)
}
}
})
That should do the trick and prevent the min/max date values firing twice.
Correct Behavior
minDate and maxDate functions should not set value if field value is empty. so if there is a value and value is out of the range, simply empty value of field. if the value is in the range do nothing.
Following on this.
Breaks an upgrade. Earlier version, working flawlessly.
Any news on this?
Yet didn't found any specific option to prevent if from printing the minDate in textbox.
Other option i used is just applied small code of jquery on window load
$(window).load(function(){
$('.dateField').val('');
})
With this user cannot select value previous then the set minDate but value will not be field.
I'm running into this issue too, but only when the date on my PC is before the value of the minDate attribute. The input is loading with a default value that is within the minDate and maxDate, but if my PC's date is before the minDate, it will refresh the datepicker input to the value of the minDate. If I view the HTML source, the value attribute of the input is still the correct date, but the textbox and the calender picker panel display the minDate.
Here is a jsfiddle with the issue:
http://jsfiddle.net/0Ltv25o8/3501/
Both inputs have a value of 05-Jan-2017 but the first one has a minDate of 01-Jan-2017 and refreshes the input to 01-Jan-2017. The second one does not have the minDate and does not update the input.
Following @tugrul suggestion. Just add a empty value to your date input value=''
<input id="booking-date-1" name="start_date" type="text" value="">
It should do the trick. It will prevent to minDate be set by default.
@levivm Setting the value to empty string does not work for me, the minDate is still displayed in the input http://jsfiddle.net/RazvanS/0Ltv25o8/3885/
@yudircks Based on https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1579, I have managed to solve this by adding "useCurrent: false" in the options object.
Trick with value="" works only if minDate less than today. In another cases it doesn't work.
This solved using option
useCurrent: false
When using useCurrent: false calendar focus in current date
following are my parameters
{ format: "DD/MM/YYYY", locale: 'ar' , maxDate: moment().add(-2, 'year'), minDate: moment().add(-150, 'year'), useCurrent: false }
i need to focus calendar to max date
@jasmalmk in your case you can remove useCurrent but I guess you don't want that the textbox set the date on the input by itself.
If that's the case just use jquery to clean the input
$("#myDatepicker input").val(null);
Most helpful comment
This solved using option
useCurrent: false