I'm working on adding the js calendar into a date field for cck. The good news is that with the latest update to form.inc the pop-up works just fine (at least for me). The form.inc cvs update took care of a bug that was setting multiple class="" attributes on the input form, and the js was ignoring the second one, which happened to be the one needed for jscalendar to work.
Now I just need some fine-tuning. In cck we are using an iso 8601 format date (YYYY-MM-DDTHH:MM:SS). By altering jscalendar.js just a bit to change:
ifFormat : "%Y-%m-%d", // the date format
to:
ifFormat : "%Y-%m-%dT%H:%M:%S", // the date format
and by adding the following to the calendar.setup
showsTime : true,
timeFormat : 12,
I can get the pop-up calendar to return a date and time in the correct format. Now I want to find a way to send those attributes to the js without actually changing the js itself (because other modules may need it working as it was originally configured). I also need sometimes to set it for 24 hour format and other times for 12 hour format, and may want to turn off the time collection at times, depending on the way the date field has been configured. Is there any way I can set those attributes at runtime? I know very little js, just enough to be dangerous, so if it requires more js, I'll need an example of exactly what the code needs to look like :-)
One other very tiny issue -- the calendar expand to fill the whole width of the page. Is there any way to get it a bit smaller? That's not a big deal, just something that might be nice to have.
Thanks for this tool. It is very nice!!
Comments
Comment #1
karens commentedOne more question. I can see that there are multiple languages available. How can these be turned on, again hopefully at runntime based either on the language of the user or the configuration of the field?
Comment #2
nedjoGood questions!
I think what we need to do is:
* Add attributes to the $form with the desired settings, e.g., $form['#jscalendar_showsTime'] = 'true';
* Add an optional 'locale' or language argument to jscalendar_load(), defaulting based on the Drupal locale.
* Use form_alter to add hidden form fields to the form, passing these settings to the browser, and using defaults based on the drupal config, e.g., time format.
* In the Javascript, read in the form's hidden inputs and set the Calendar.setup accordingly.
The calendar width bug is now fixed. Do a fresh download (it might need to be repackaged).
I'll get to this when I get a chance. Feedback on the approach meantime would be great.
Comment #3
nedjoThanks KarenS, committed an interim change making your suggestions the defaults.
Comment #4
karens commentedThanks for the quick response. Yes, your approach for making runtime changes sounds like it would work.
I ran into a small problem with the iso configuration, though. If I use the format YYYY-MM-DDTHH:MM:SS it updates the field correctly when I click on the items in the calendar, but when I come back to that field later it gets the date right, but the time wrong. In playing around with it I found that if I changed the format to YYYY-MM-DD HH:MM:SS it correctly picks up both the time and date when I come back to the field, so it looks like that 'T' is throwing it off. I don't know if there is any way to get it to behave correctly with the 'T' in there. If not, we could configure it without the 'T' and I can swap the 'T' in and out when the field is retrieved and saved.
Comment #5
nedjoMost or all of the discussed changes are now implemented. We now don't have to invoke jscalendar_load--it's done automatically as needed. Please test and, if it's working well, set this issue to fixed.
Here's instructions from the README:
Adding to a textfield
----------------------
To include a jscalendar popup with a textfield, just add the class 'jscalendar':
Customization
----------------------
To change the default display and functionality of the calendar, set startup parameters by adding selectors to your form. The three configurable options are 'ifFormat' (the format of the date/time written to the text field), 'showsTime' (boolean: should time be displayed on the calendar), and 'timeFormat' (values of '12' for 12-hour clock, which is the default, or '24' for 24-hour clock).
Examples:
Localization
----------------------
Jscalendar comes with numerous localization files, see the /lib/lang directory. By default, the module will look at the current Drupal $locale and load an appropriate localization file, defaulting to 'en' for unsupported languages. To explicitly set the localization file to be used, call jscalendar_load() with your desired localization as the argument. Example:
Comment #6
karens commentedAll of this seems to work fine. I have one other feature request, but I will submit it as a separate issue.
Comment #7
(not verified) commented