user932205
user932205

Reputation: 37

Disabling multiple dates/date range in DateTextbox in dojo

I want to use dateTextBox in Dojo for user to select date.And i want to restrict my date selection only for the next 10 days(excluding weekends).

So if my date starts on monday(30/6/2014) then it should be enable for monday(30/6/2014) to friday(04/07/2014), then disabl for saturday(05/07/2014)-sunday(06/07/2014) and again enable for monday(07/07/2014) to friday(11/07/2014).

- thanks in advance.

Upvotes: 1

Views: 1293

Answers (1)

Dimitri Mestdagh
Dimitri Mestdagh

Reputation: 44685

You can disable specific dates by overriding the rangeCheck function, for example:

var SUNDAY = 0, SATURDAY = 6, TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
registry.byId("myDate").set('rangeCheck', function(date, constraints) {
    var isValid = date.getDay() !== SUNDAY && date.getDay() !== SATURDAY; // Weekend check
    var today = new Date();
    today.setHours(0, 0, 0, 0);
    var diffms = date.getTime() - today.getTime();
    isValid &= diffms >= 0 && diffms <= TWO_WEEKS; // Two week check
    return isValid;
});

I'm using the curent day here to get the next two weeks, but you could add a specific date in your constraints, which are passed to the rangeCheck function as well.

A full example can be found on JSFiddle: http://jsfiddle.net/rkC9h/

Upvotes: 1

Related Questions