jquery datepicker date restriction not working

307
June 11, 2017, at 11:13 PM

I try to restrict a picker by value from another picker. I looked other questions here but they seem to be outdated and not work

What I do is following

<p><input type="text" id="startdatepicker"></p>
<p><input type="text" id="enddatepicker"></p>
$(function() {
    $("#startdatepicker")
        .datepicker({ minDate: -1, maxDate:"" })
        .datepicker("option", "dateFormat", "dd.mm.yy");
});
$(function() {
    $("#enddatepicker")
        .datepicker({
            minDate: $("#startdatepicker").datepicker("getDate"), 
            maxDate: ""
        })
        .datepicker("option", "dateFormat", "dd.mm.yy");
});

How to do this correctly ?

Answer 1

This is fairly straightforward to accomplish:

$(function() {
    $("#startdatepicker, #enddatepicker")
        .datepicker({
            minDate: -1,
            dateFormat: "dd.mm.yy",
         })
     ;
    $('#enddatepicker')
        .datepicker('option', 'disabled', true);
    $('#startdatepicker').on('change', function(){
        var datestamp = this.value.split('.');
        datestamp = new Date(
            +datestamp[2],
            +datestamp[1],
            +datestamp[0]
        );
        if (!datestamp) return false;
        $('#enddatepicker')
            .datepicker('option', 'disabled', false)
            .datepicker('option', 'minDate', datestamp)
        ;
    });
});

https://jsfiddle.net/zvc1p8xk/

READ ALSO
multiple dependent dropdown using jquery

multiple dependent dropdown using jquery

I have used the following code to run two different dependent dropdown listSubdivision depends on District and Dress depends on Gender

285
How to get the value &ldquo;value&rdquo; of a button that called a function

How to get the value “value” of a button that called a function

I'm currently into a place where I call an Api with Ajax to delete a Client from a table I'veThe thing is, that I've previously tried to make a check before ajax is executed, but it doesn't seem to work

282
Segregate front end from back end

Segregate front end from back end

Could someone suggest me on how can i implement the below design

263
Run demo page using Jquery and JS in angularjs2

Run demo page using Jquery and JS in angularjs2

I want to create separate demo directory where I will have native JS files and landinghtml

368