2

I sure do love jQuery. It has some great date pickers available for it. But I'm looking for something a bit more custom and don't know how to program it. If you've got a suggestion for me, I'd greatly appreciate it.

It would have two requirements:

  • The date selected would always be three days out from the current date.
  • Weekends (U.S./Saturday and Sunday) wouldn't be available. Weekdays only.

I guess that's it. I stand on the shoulders of giants. Thanks for any help you can give in advance.

rumblestrut
  • 159
  • 2
  • 2
  • 10
  • 2
    Actually you can do this with jQuery UI's Datepicker. – kapa Jun 24 '11 at 15:59
  • why not use the datepicker from jquery and use the date range, ? ? http://jqueryui.com/demos/datepicker/#min-max this example has a date range of 2-3 months I think but you can always change it – Val Jun 24 '11 at 16:00
  • This SO answer should help: http://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holida/503082#503082 – Adrian J. Moreno Jun 24 '11 at 16:04

2 Answers2

2

Actually you can do this with jQuery UI's Datepicker.

You'd need something like this:

$("#your_date_input").datepicker({ 
    minDate: -3, 
    maxDate: 3,
    beforeShowDay: $.datepicker.noWeekends
});

This will make those weekdays selectable that are 3 days from today (into past and future as well). If you need something more complex, it is easy to write your own beforeShowDay function, check the documentation. There are also lots of jQuery UI Datepicker questions here on StackOverflow, so you can easily get help.

No need to reinvent the wheel, if we have great tools available.

kapa
  • 77,694
  • 21
  • 158
  • 175
  • 2
    Verified as working, for the curious: http://jsfiddle.net/Ender/RsBck/ +1, bazmegakapa – Ender Jun 24 '11 at 16:12
  • @Ender Thanks a lot, I could not make a Fiddle myself now. – kapa Jun 24 '11 at 16:13
  • If his "three days out from the current date" does not include weekends, though this would not work. For example, if today was Wednesday he wouldnt be able to select the proper date (the following Monday). – Josh Mein Jun 24 '11 at 16:17
  • @jmein As I read the question, this was not a requirement. Anyways, I just wanted to show how flexible the jQuery UI Datepicker is. If someone wants it the way you said, it is easy to write an appropriate `beforeShowDay` handler, certainly much easier, than writing a whole datepicker (which is the original question, and I wanted to provide an alternative). – kapa Jun 24 '11 at 16:21
  • 1
    Thank you, you excellent wonderful people. @Ender, your answer helped also FWIW. In the end, what I was looking for was this: $( "#datepicker" ).datepicker({ minDate: 3, beforeShowDay: $.datepicker.noWeekends }); Perfect! Thank you! Thank you! – rumblestrut Jun 24 '11 at 16:46
0

You can create a custom Jquery datepicker like this: http://www.share-your-experiences.com/viewtopic.jbb?t=16&Create-a-custom-jquery-datepicker-in-your-language

Guest
  • 1