2

I am using Zebra Datepicker and have a start date and end date. I am looking for help with code that would help me with this:

Start date should be up to today (should not be in the future) End date should be from the start of the Start date choice to today (No future date).

I started with this but cannot seem to get any further.

$(document).ready(function() {
    var $zdp = $('#element').data('Zebra_DatePicker');
$('#from').Zebra_DatePicker({
    direction: false,
    format: 'm/d/Y',
    view: 'years',
    show_icon: true,
    pair: $('#to')
    });
$('#to').Zebra_DatePicker({
    format: 'm/d/Y',
    view: 'years',
    direction: true
}); 

});

kofboat123
  • 31
  • 1
  • 4

3 Answers3

3

I just came to this issue myself and solved it easily by reading the zebra datepicker documentation:

A positive or negative integer: n (a positive integer) creates a future-only calendar beginning at n days after today; -n (a negative integer) creates a past-only calendar ending n days before today; if n is 0, the calendar has no restrictions. use boolean true for a future-only calendar starting with today and use boolean false for a past-only calendar ending today.

So your code should change to:

$(document).ready(function() {
    var $zdp = $('#element').data('Zebra_DatePicker');
    $('#from').Zebra_DatePicker({
        direction: true,
        format: 'm/d/Y',
        view: 'years',
        show_icon: true,
        pair: $('#to')
    });
    $('#to').Zebra_DatePicker({
        direction: true
        format: 'm/d/Y',
        view: 'years',
    }); 
});

The only change made is that I changed the direction of #from to true. As stated in the documentation your #to direction is correct.

Thanasis Pap
  • 2,031
  • 2
  • 17
  • 19
1

Just add -1 in direction instead of false

$('#from').Zebra_DatePicker({
        direction: -1,
        format: 'm/d/Y',
        view: 'years',
        show_icon: true,
        pair: $('#to')
     });
Sanket Utekar
  • 327
  • 4
  • 12
1

Using an external library like moment.js, you should format the current date (today) for using it in the direction option of the second datepicker this way:

var end_date = moment().format("m/d/Y");

$('#to').Zebra_DatePicker({
  direction: [true, end_date]
  format: 'm/d/Y',
  view: 'years',
});

This way, the second datepicker will start with the date selected in first datepicker, and will end today since end_date will have the current date.