I need to create a jQuery ui datepicker that will let users choose a start week of the year, and an ending week of the year. IE: Always Sunday – Saturday. Is this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
DatePicker can restrict a user’s selection, but only as far as restricting the user between two dates (
minDateandmaxDateoptions). As far as I’m aware, there’s no built in functionality that can restrict selection to only Sundays or Saturdays.DatePicker does however have a means of calculating the week of a user’s selection with the following snippet of code:
You can see how this could be utilised in the following jsFiddle (read below, first).
The only problem with this is that the ISO-week always starts with a Monday. So even though in the demo above I have set Sunday to be the first day of the week, if you try selecting the date
Wed 7th March 2012you’ll see in the datapicker it shows as week 9, where the ISO-week will return 10. I left it in on purpose to show you this pitfall.Although this doesn’t provide a direct solution to your problem, hopefully it’ll help in determining if you should use DatePicker at all to produce your desired functionality.
edit
Actually, just found this question which might be of use to you, looks like it’s possible : Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?