Limit date/time element.

prophoto

Active Member
I have a form that the client needs to allow the user to choose an appointment date. It is pretty basic, just need to prevent past dates and Sundays, which I have figured out from the forum and wiki.

Code:
var result = true;
var d = new Date(date);
var n = d.getDay();
var diff = new Date().compare(new Date(date));
if ( (n > 0) && (diff > 0) ) {
result = false;
}

Next step I need is to limit the hours to 30 minute increments from 8-4pm MTWF, 8-6pm Thurs and Saturday 9-4pm. I figure I will need to setup another table with open hours and time cdd to make this work. Any other suggestions? Still learning js so be easy on me ;0)
 
Not quite sure what you mean. Do you need to black out time slots which are already taken?

Are you wanting to do this with the time selector on the date element, or a separate time dropdown / join?

-- hugh
 
Hmmm, well nothing about that is easy, lol.

But yes, start with a table of valid slots for each day of the week. Rather than go for a CDD, I'd just have a table of slots, like ...

id, slot
1, 8:00am
2, 8:30am
...
16, 6:00pm

... and a table of day number/slot (lets call it day_slots)

id, daynum, slot_id
x,2,1
x,2,2
..
x,2,12
x,3,1
x,3,2
...
x,3,12
...

So a daynum/slot for every valid time slot (so something between 12 and 16 rows per day number), and numbering the days starting with 1 for Sunday (so no entries for 1).

Then in the WHERE clause for the slots join on "yourtable", something like ...

WHERE {thistable}.id IN (SELECT slot_id FROM day_slots WHERE daynum = DAYOFWEEK('{yourtable___date}'))

... and set AJAX update on the where.

That should handle showing the right slots for each day.

Once you have that going, we'll figure out how to black out slots which are already taken, which will involve extending that WHERE clause to find the already booked slots for that day. Which I think would be something like ...

WHERE {thistable}.id IN (SELECT slot_id FROM day_slots WHERE daynum = DAYOFWEEK('{yourtable___date}')) AND {thistable}.id NOT IN (SELECT slot FROM yourtable WHERE DAYOFWEEK(date) = DAYOFWEEK('{yourtable___date}'))

-- hugh
 
I have this setup and working. I don't need to block out spots for now, possibly in the future. The one issue I am seeing is sometimes when a form is filled out the time element will show the slot id instead of the actual time in the email.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top