jQuery MultiDatesPicker for datepicker:限制范围? [英] jQuery MultiDatesPicker for datepicker: Restrict range?

查看:161
本文介绍了jQuery MultiDatesPicker for datepicker:限制范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(#datepicker).datepicker({minDate:-20,maxDate:+ 1M + 10D}); 

从API文档中 p>


支持多种类型:



日期:包含最低日期的日期对象。



号码:从今天起的几天。例如2代表从今天起的两天,-1代表昨天。



String :由dateFormat选项定义的格式的字符串,或相对日期相对日期必须包含值和周期对;
有效期为y,多少个月为m,w为几个星期,而
d为几天。例如,+ 1m + 7d表示从今天起的一个月和七个
天。



I decided to use this addon for the jQuery UI Datepicker,

Wich seems to work great, for example:

$(function () {
    var today = new Date();
    $('#test').multiDatesPicker({
        dateFormat: "yy-mm-dd",
        addDisabledDates: [today.setDate(1), today.setDate(3)]
    );
});

This allows user to select as many days as he wants except the 1st and the 3rd of current month,

but how could I restrict the user to select dates only greater than a desired date (start) and smaller than another desired date?

I don't see any method for that in their documentation

PD: As a workaround, it ocours to me to create an array with the dates before/after my desired interval, but how could I mark it all? (I mean, how many years should I contempl in this array??)

-EDIT-

Just to test, I am trying to disable the 15 days before and 15 days after from my desired range, like this:

$(function () {
        var start = new Date(2013, 11, 20)
        var end =  new Date(2013, 11, 24)

        console.log(start, end);

        var dissabledDates = [];
        if ( end < start ) {
            alert('Está mal');
        }

        for ( i = 0 ; i < 15 ; i++ ){
            var currentDate = new Date();
            currentDate.setDate( start.getDate() - i );
            dissabledDates[ dissabledDates.length ] = currentDate;
        }
        for ( i = 0 ; i < 15 ; i++ ){
            var currentDate = new Date();
            currentDate.setDate( end.getDate() + i );
            dissabledDates[ dissabledDates.length ] = currentDate;

            console.log(currentDate);
        }


        var today = new Date();
        $('#test').multiDatesPicker({
            dateFormat: "yy-mm-dd",
            addDisabledDates: dissabledDates
        });
    });

And the restriction happens, but, look how the selector looks (note I only restricted 15 days before and after)

so question is: how can I only let user select between my start and end dates?

解决方案

Utilize the base functionality from the jQuery UI datepicker as stated here

$( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });

From the API documentation:

Multiple types supported:

Date: A date object containing the minimum date.

Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.

String: A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.

这篇关于jQuery MultiDatesPicker for datepicker:限制范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆