two datepickers, set 2nd datepicker to NOT be able to select dates prior to the first.

285 views
Skip to first unread message

José Luis Chafardet Grimaldi

unread,
Jun 21, 2016, 2:25:48 PM6/21/16
to bootstrap-datepicker
Hey guys! I have the following code (not working as to be expected)

var fullDate = new Date();
var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);
var currentDate = fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
jQuery
(document).ready(function() {
    jQuery
('#desde').datepicker({
        startDate
: currentDate,
        language
: "es",
        autoclose
: true,
        todayHighlight
: true,
        keyboardNavigation
: false,
   
});

    jQuery
('#hasta').datepicker({
        setStartDate
: jQuery('#desde').datepicker('getFormattedDate'),
        language
: "es",
        autoclose
: true,
        todayHighlight
: true,
        keyboardNavigation
: false,
   
});
}

The idea is to have 2 datepickers, where the first datepicker value should set the minimum date to be selected from the 2nd. its imperative that you cannot select dates from the past (the minimum date from the first datepicker must be "today" and the minimum date from the second datepicker must be first-datepicker value)

due to restrictions of the design, it cannot be a date-range picker.

Any cues or pointers around?



Artem K

unread,
Sep 5, 2016, 9:14:25 AM9/5/16
to bootstrap-datepicker
Hello,
you need to call method 'setStartDate' from the code. It's not the options part.

E.g. you can fire some function on date change event in you start date container. Something like this:

jQuery('#desde').datepicker().on('changeDate', function(e) {
                jQuery('#hasta').datepicker('setStartDate', $(this).datepicker('getDate'));
});
Reply all
Reply to author
Forward
0 new messages