I understand how to use the onDate function to check dates and return {selectable:false} to stop a date from being selectable.
But I can't get my head round how to do this if there are multiple date_popup fields which have different selectable dates (both the number of fields and the dates for each are variable) - how do I find the right instance of the datepicker and assign the right function/settings.
Any clues would be appreciated.
(Of course it would be lovely if the date_popup fields had a '#disallow_dates' field - or in my case '#allow_fields' since I have more disallowed than allowed but until then ... any ideas?)
TIA
Comments
Comment #1
adaddinsaneIs it impossible?
Comment #2
adaddinsaneWell, not entirely but it's been made hard.
Can I make some comments?
Currently the date_popup element overwrites the #theme_wrappers which is frustrating because it means I can't intercept any actions on that element.
However that wouldn't have helped anyway, because rather than using "#attached" to add the Javascript and settings, the module writes them directly with drupal_add_js().
If '#attached' was used I could have used #theme_wrappers to intercept and modify the settings to add the necessary code to disallow dates. (Adding my function and the disallow dates to the options.)
Obviously there is hook_js_alter() but I'll have to create spaghetti code to figure out which dates belong to which set of settings (even assuming I can - I haven't looked yet).
(Not that I don't appreciate the work - I really do, it's just that I need this and I can't have it.)
Comment #3
karens commentedIf you know of a better way to do it that won't break other things, propose a patch.
Comment #4
adaddinsaneHi Karen - sorry if it came across as unhappy. I know you've put in a huge amount of work over the years. Trouble is I have three days to finish this commercial project and it's a brick wall.
Anyway I'll be seeing what I can do in a day or so.
Comment #5
adaddinsaneOkay. I've done it :-)
Not as hard as you might expect but a bit fiddly because the 'beforeDayShow' callback gives you the date, but not the element so there's a bit of jiggery-pokery to make sure we select the right dates.
I've got a patch which I've attached - but its type is txt, sorry I run on Windows which can be a pain sometimes. I have no idea if the patch will work so I've also attached a zip of the module with the new code.
We have two new options: with '#date_disallow' all dates are allowed except the ones specified, while with '#date_allow' all dates are disallowed except the ones specified.
I haven't touched anything else in the code.
Comment #6
adaddinsaneOoops, forgot to remove the debug code - just uploading the patch this time.
Also doesn't currently check the dates in the element validation.
Comment #7
adaddinsaneAnd that patch didn't work because of GMT/BST issues - I guess it's pretty limited on that front.
Anyway here's a newer version...
Comment #8
arlinsandbulte commentedDate 7.x-1.x is unsupported.
This issue should be verified in the latest version of Date (7.x-2.x-dev) and re-opened if still valid.
Thanks
Comment #9
arlinsandbulte commentedshould have marked "won't fix" instead