Flatpickr multiple datepicker in same page - datepicker

I realize a site in symfony and I use the flatpickr library for the selection of dates. that's what it's like now:
datepicker
So I have 2 datepicker who uses flatpickr which allows me to select a departure date with the time and a date back with the time too. My problem, when I select the first date, flatpickr shows me well the time selection but when I go on the second datepicker I can not select the time.
datepicker 1
datepicker 2
I wish I could select in the 2 inputs the date and the time.
Here is my JS code of my 2 inputs:
var departure = $('#quick_booking_departure');
var arrival = $('#quick_booking_arrival');
departure.flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
position: "above",
disableMobile: true,
locale: "fr",
minDate: "today",
onChange: function (selectedDates, dateStr, instance) {
arrival.flatpickr({
minDate: dateStr
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
});
arrival.flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
position: "above",
disableMobile: true,
locale: "fr",
minDate: "today",
onChange: function (selectedDates, dateStr, instance) {
departure.flatpickr({
minDate: 'today'
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
});
Thank you for your help.

It looks like your onChange function is the culprit adding enableTime: true allows time pick:
onChange: function(selectedDates, dateStr, instance) {
arrival.flatpickr({
enableTime: true,
minDate: dateStr
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
But look closer, when one of your pickers change you are completely re-initializing the other. So all the options you originally defined are getting reverted back to default except for what you are re-defining minDate

Related

Bootstrap Datepicker set Minimum Range

We are using Bootstrap Datepicker (https://github.com/uxsolutions/bootstrap-datepicker) to set a checkin and checkout date.
We need to be able to set a 'minimum range' on the date picker for properties that have a minimum night stay.
Missing Requirements:
Do not allow # of nights to be less than property nightly minimum.
Do not allow checkout date to be before checkin date.
So, if a visitor selects the checkin date of 12/01/2017, and the property has a minimum night stay of 3 nights, the visitor should not be allowed to select 12/02/2017, 12/03/2017. The next available night for them to checkout on should be 12/04/2017.
I'm not seeing that this is a simple option with this date picker. I do see that it has been added as a feature request by quite a few though.
https://github.com/uxsolutions/bootstrap-datepicker/issues/970
I've built the start of what might be able to work by using the disabledDates and setDatesDisabled dates. Yet, I can't seem to figure out why these disabledDates are not working or firing when selecting a new start date. I think that I should be able to combine the newly set disabled dates with those already posted.
$(function($) {
var today = new Date();
$('.input-daterange').datepicker({
daysOfWeekHighlighted: "0,6",
autoclose: true,
todayHighlight: true,
startDate: today,
datesDisabled: ['10/1/2017','10/2/2017','10/3/2017','10/4/2017','10/5/2017','10/6/2017','10/7/2017','10/8/2017','10/9/2017','10/10/2017','10/11/2017','10/12/2017','10/13/2017','10/14/2017','10/15/2017','10/16/2017','10/17/2017','10/18/2017','10/19/2017','10/20/2017','10/21/2017','10/22/2017','10/23/2017','10/24/2017','10/25/2017','10/26/2017','10/27/2017','10/28/2017','10/29/2017','10/30/2017','10/31/2017'],
});
});
// Set end date to minimum nights.
$('#start').on('change', function() {
// Set minNights.
minNights = 3;
start = $('#start').datepicker('getDate');
end = moment(start).add(minNights, 'day').toDate();
$('#end').datepicker('update', end);
$('.input-daterange').datepicker('setDatesDisabled', [ $('.input-daterange').datepicker('setDatesDisabled', ['12/02/2017', '12/03/2017']);]);
});
Is there another date picker that has this built in already? Or, is there a simple and clean way to add the missing requirements above to the bootstrap datepicker?
Simple JSFiddle
https://jsfiddle.net/riverecho/omd5uw21/
Give this a try
$(function () {
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
showButtonPanel: true,
changeMonth: true,
changeYear: true,
yearRange: '1999:2012',
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
minDate: new Date(1999, 10 - 1, 25),
maxDate: '+30Y',
inline: true
});
});

Can't open pickatime, picker.open() is not a function

I've a problem to open the timepicker of pickadate.js
I've tried to open it with the code below but it doesn't works for me.
I get an error : "picker.open() is not a function".
this my js code :
$('.timepicker').pickatime({
default: 'now', // Set default time
fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
twelvehour: false, // Use AM/PM or 24-hour format
donetext: 'OK', // text for done-button
cleartext: 'Clear', // text for clear-button
canceltext: 'Cancel', // Text for cancel-button
autoclose: true, // automatic close timepicker
ampmclickable: false // make AM PM clickable
});
$('#test').click(function () {
event.stopPropagation();
event.preventDefault();
var picker = $('.timepicker').pickatime('picker');
picker.open();
});
A weird thing : I tried to open a pickadate object with the same method and it works perfectly ..
Do you have a solution to avoid it ?
thanks for helping
Haven't quite figured out why, but for me the following works:
Instead of
picker.open();
do
picker.data('clockpicker').show();
Hope that helps!
It's too late to answer but it will help others.
var picker = $('.timepicker').pickatime({
default: 'now', // Set default time
fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
twelvehour: false, // Use AM/PM or 24-hour format
donetext: 'OK', // text for done-button
cleartext: 'Clear', // text for clear-button
canceltext: 'Cancel', // Text for cancel-button
autoclose: true, // automatic close timepicker
ampmclickable: false // make AM PM clickable
});
$('#test').click(function () {
event.stopPropagation();
event.preventDefault();
// var picker = $('.timepicker').pickatime('picker');
picker.open();
});
reference

How to select between date range on a materialize date picker

I have a materialize date picker which allows me to select between 10 days in current date.
But i want to select between 16/05/2016, 19/05/2016 dates and other dates will be disabled on the date picker (user cannot select other dates).
My Materialize Date Picker Code :
$('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 10, // Creates a dropdown of 10 years to control year
format: 'dd/mm/yyyy',
min: -10,
max: true,
closeOnSelect: true,
closeOnClear: true,
});
Did you try this:
$('.datepicker').pickadate({
min: new Date(2015,3,20),
max: new Date(2015,7,14)
})
or this:
$('.datepicker').pickadate({
min: [2015,3,20],
max: [2015,7,14]
})
Otherwise selectmonths & selectyears may cause problem. If you select only 10 days range, you do not need selecting years or month. Try like this:
$('.datepicker').pickadate({
format: 'dd/mm/yyyy',
min: -10,
max: true,
closeOnSelect: true,
closeOnClear: true,
});
http://amsul.ca/pickadate.js/date/

End date must be equal and greater than start selected date in boostrap

Requirements - End date must be equal and greater then start selected start date in boostrap datepicker and before selected start date disable.
Problem - its possible in jquery date but I want to know how to make in boostrap date.
my boostrap code is
$('#start_date').datepicker({autoclose: true,startDate: new Date()});
$('#end_date').datepicker({autoclose: true,startDate: new Date()});
for reference check jquery code
Fiddle
Note - I want exact implemention of this picker in bootstrap
Can anyone help me?
Please check out this JSFiddle demo. I have placed the code below that uses bootstrap datepicker.
$(".from_date").datepicker({
format: 'yyyy-mm-dd',
autoclose: true,
}).on('changeDate', function (selected) {
var startDate = new Date(selected.date.valueOf());
$('.to_date').datepicker('setStartDate', startDate);
}).on('clearDate', function (selected) {
$('.to_date').datepicker('setStartDate', null);
});
$(".to_date").datepicker({
format: 'yyyy-mm-dd',
autoclose: true,
}).on('changeDate', function (selected) {
var endDate = new Date(selected.date.valueOf());
$('.from_date').datepicker('setEndDate', endDate);
}).on('clearDate', function (selected) {
$('.from_date').datepicker('setEndDate', null);
});

adding bounce animation to date picker

I have a date picker using jquery. However I want to add the 'bounce' animation to it. Please help me adding this animation to the date picker. My code as of now is:
$(function() {
$("#datepicker").datepicker({ dateFormat: "DD, d MM, yy" });
});
Is this what you are trying to accomplish?
$(function() {
$("#datepicker").datepicker({ showAnim: "bounce", dateFormat: "DD, d MM, yy" });
});
http://jsfiddle.net/damyanpetev/VS2hV/
Additionally you can set duration and additional options that correspond to the effect you are using (in this case 'bounce' .