Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2013, 11:19 AM   PM User | #1
McG
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
McG is an unknown quantity at this point
JQuery Datepicker

Hi all,
I'm a CF and JS newbie, so any help would be grateful.
I'm looking for some help on excluding dates from the jQuery datepicker.
The rules for excluding dates are a little complicated, at least to me.

The datepicker is used for choosing an earliest collection date, but the collection date is depended on when you placed the order within business hours.

So...
It needs 48 hours minimum notice in general - easy to do with setting the minDate.
But it gets complicated with orders placed before & after 12pm, and orders placed at weekend.
The break down for earliest collection...

Monday before 12pm = Wednesday / after 12pm = Thursday
Tuesday before 12pm = Thursday / after 12pm = Friday
Wednesday before 12pm = Friday / after 12pm = Saturday
Thursday before 12pm = Saturday & Sunday / after 12pm = Monday
Friday before 12pm = Monday / after 12pm = Tuesday
Saturday & Sunday = Wednesday


Im new to JS, but I have the following code

Any help would be grateful.
Martin

Code:
var dt = new Date();

function time() {
      return dt.getHours() >= 12 ? '+3d' : '+2d';
}

$("input[value*='EnterDate']").val('').datepicker({

minDate:time(),

});
McG is offline   Reply With Quote
Old 01-28-2013, 03:45 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
this is probably best handled with a switch - assuming that the code you have works ok for weekday orders, just give it special instructions for Saturday (6 in javascript) or Sunday (0)...

Code:
var dt = new Date();

function time() {
    var day = dt.getDay();
    switch (day) {
        case 6:
            var deliv = '+4D';
            break;
        case 0:
            var deliv = '+3D';
            break;
        default:
            var deliv = dt.getHours() >= 12 ? '+3D' : '+2D';
            break;
    }
    return deliv;
}

$("input[value*='EnterDate']").val('').datepicker({

    minDate: time()

});
(the datepicker doc uses capital "D" for the mindate property, although I suspect that jQuery can handle lowercase, too)

... and the trailing comma you had after minDate: time() is a very bad habit - maybe jQuery strips these out by default, but if you do that in plain javascript, IE will wet its pants because it expects something to come after the comma - commas should only go between things, for example if you were coding maxdate as well it would be:

Code:
$("input[value*='EnterDate']").val('').datepicker({
maxDate: getSomeOtherTime(),
minDate:time()
});
AND (ha, ha - sorry, but I'm anticipating the next problem)... I notice that you are not using the datepicker with an element's ID... you should be aware that each input needs its own datepicker - you can't use the same one for all of them
xelawho is offline   Reply With Quote
Old 02-04-2013, 02:47 PM   PM User | #3
McG
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
McG is an unknown quantity at this point
Thanks Xelawho,
Its working fine.

Ive got it in a JSfiddle and was trying to test each day by giving the dt variable a date value.
Im not getting the adjustment in the picker.


http://jsfiddle.net/MGMcG/ArMur/


Regarding the element ID. I'm trying to implement a datepicker in a hosted ecommerce platform. I cant get full access to the code, but by creating an input with a value of EnterDate, I was thinking of identifying by that value. Its not ideal, but it sort of works.


Thanks for the tips also on my bad habits. I'll keep an eye on it.

Again, any help would be grateful.
McG is offline   Reply With Quote
Old 02-04-2013, 02:52 PM   PM User | #4
McG
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
McG is an unknown quantity at this point
Sorry, this was a double post

Thanks
Martin

Last edited by McG; 02-04-2013 at 07:34 PM.. Reason: Double Post
McG is offline   Reply With Quote
Old 02-04-2013, 04:41 PM   PM User | #5
McG
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
McG is an unknown quantity at this point
Sorry this was a double post.

Last edited by McG; 02-04-2013 at 07:35 PM.. Reason: double post
McG is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:41 AM.


Advertisement
Log in to turn off these ads.