简体   繁体   中英

Date Range Picker - IsInvalidDate / IsCustomDate

I currently am using DateRangePicker by http://www.daterangepicker.com and have the following code for my project :

<form name="calform" action="res_info.php">
<div>Checkout<input type="text" name="checkout"/></div>
<script type="text/javascript">

$(function() {
isInvalidDate: function(date) {
    if (date.format('YYYY-M-D') == '2017-11-12') {
        return true; 
    }
}
    $('input[name="checkout"]').daterangepicker({
        singleDatePicker: true,
        "locale": {
        format: 'YYYY-M-D'
  }
    }, 
    function(start, end, label) {
        var years = moment().diff(start, 'years');
    });
    $('.calendar.right').show();
});
</script>
   <div> <input type="submit" value="Submit"></div>
</form>

But for some reason , isInvalidDate function doesn't work at all. Please Help.

isInvalidDate appears to be a method of daterangepicker . As your code currently goes, that method is outside of scope of the daterangepicker object/function.

You'll need to place it inside like so:

$('input[name="checkout"]').daterangepicker({
    singleDatePicker: true,
    "locale": {
        format: 'YYYY-M-D'
    },
    isInvalidDate: function(date) {
        if (date.format('YYYY-M-D') == '2017-11-12') {
            return true; 
        }
    }
});

Additionally, it looks like the code will still be malformed. You have a, what i would consider random, function in the daterangepicker object. I'd read the documentation, to get a better understanding of the use of that function.

http://www.daterangepicker.com/#options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM