1

In Bootstrap datepicker how to disable all dates from previews to Start Date on End date? In simple theres 2 datepicker input when first input gets date second input dates are limited to only after dates from first input date. Thanks

1 Answers1

0

minDate must be another date picker's maxDate:

datepicker.on( "change", function() {
      to.datepicker( "option", "minDate", getDate( this ) );
    })

you can apply this solution to any Jquery dateicker:

$( function() {
    var dateFormat = "mm/dd/yy",
      from = $( "#from" )
        .datepicker({
          defaultDate: "+1w",
          changeMonth: true,
          numberOfMonths: 3
        })
        .on( "change", function() {
          to.datepicker( "option", "minDate", getDate( this ) );
        }),
      to = $( "#to" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 3
      })
      .on( "change", function() {
        from.datepicker( "option", "maxDate", getDate( this ) );
      });
 
    function getDate( element ) {
      var date;
      try {
        date = $.datepicker.parseDate( dateFormat, element.value );
      } catch( error ) {
        date = null;
      }
 
      return date;
    }
  } );
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
Vikrant
  • 4,920
  • 17
  • 48
  • 72
  • @user2223293, you tried the solution? is it working? U can **up** my answer – Vikrant Nov 07 '16 at 05:47
  • yeah its working, but its for jquery datepicker. I need one for Bootstrap Datepicker. I tried http://stackoverflow.com/questions/14409779/bootstrap-datepicker-how-to-set-the-start-date-for-tomorrow but somehow StartDate is not working – user2223293 Nov 07 '16 at 06:57
  • and I cant vote up it seems like I need 15 rep to vote – user2223293 Nov 07 '16 at 06:58
  • no issues. U can check in *tick* under my answer. As it's relevant solution – Vikrant Nov 07 '16 at 06:59
  • jQuery(function () { jQuery('.input-date, .input-daterange').datepicker({ format: "yyyy/mm/dd", startdate: "2016/11/11" }); }); startdate does not show as option on autocomplete and not working. Enddate as well – user2223293 Nov 07 '16 at 07:14