views:

52

answers:

2

I'm creating a Drupal form with a datetime-based javascript popup calendar input that allows users to set a date for when they want to pick something up or drop it off. However, I can't find a way to limit what dates are selectable as input. For example, if we're only open Monday-Wednesday-Friday, I don't want people to be able to use the selector to indicate they want a pickup on Sunday.

I've looked far and low for calendar input validation and a usable blocking mechanism, but so far no luck.

A: 

I think your best bet is to find the simplest datepicker you can find (because simplest usually == easiest to modify) and just hardcode it to skip over the days you don't want when it's building the datepicker.

However, that only fixes the JS side of it, so you'll probably want to write a little tiny custom module that does server side validation as well.

Mike Crittenden
Thanks! I'll definitely remember to check the server-side validation. It'll be a growing experience for my nascent PHP :)
Michael Morisy
A: 

Drupal uses the jQuery datepicker to pick dates. I haven't looked at how the Date module implements the js, but you can probably add extra options to it. Alternatively, you can just add the datepicker yourself. You can get what you want with the jQuery datepicker pretty easily:

$("#test").datepicker({
    beforeShowDay: function(date) {
        if (date.getDay() % 2 == 1 && date.getDay() < 6) {
            return [true];
        }
        else {
           return [false];
        }
    }
});

beforeShowDay is a function that is run for each day and should return a list where first item is a boolean that decides if you day is selectable. The second value is an optional class to add and there is a third that can be used as well, but can't remember what that is for right now.

googletorp
Thanks a lot Googletorp. I'll give this a go and see how it works!
Michael Morisy