Currently the jscalendar settings (ifFormat, etc...) are set up by adding keys ('#jscalendar_ifFormat' etc... ) to the ROOT of form.
This means one set of settings for all the jscalendar-enabled widgets in the form. This does seem an unnecessary restriction.
Plus this restricts the way you can delegate the form building to helper functions :
$form['my_date_widget'] = the_relevant_function($args);
Here, the_relevant_function might return a jscal-enabled form element, but not specify its settings, since it doesn't have access to the form root.
There are workarounds, obviously, and I even _think_ cck node form building code happens to be compatible with the current behaviour, but wouldn't it be much more natural to have the '#jscalendar_*' keys attached to the form element ?
$form['date_widget'] = array(
'#type' => 'textfield',
'#attributes' => array('class' => 'jscalendar'),
'#jscalendar_ifFormat' => 'whatever',
);
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | jscalendar.patch_0.txt | 6.52 KB | stefano73 |
| #22 | jscalendar.patch.txt | 2.02 KB | stefano73 |
| #19 | jscalendar.module.patch | 820 bytes | yched |
| #8 | README.txt_1.patch | 1.09 KB | yched |
| #2 | jscalendar_1.patch | 4.8 KB | yched |
Comments
Comment #1
yched commentedAttached patch does that.
Comment #2
yched commentedupdate - forgot to remove an unnecessary function
Comment #3
yched commentedBTW, the jscalendar-enabled contrib modules I'm aware of (that is date.module, event.module) do rely on the 'per widget' settings format.
You can find the following in event.module, for instance :
Meaning these settings are currently not taken into account.
Comment #4
karens commentedThe event and date modules use the per-widget settings because that is what http://drupal.org/node/57981 said to do. I'm going to do some testing with and without this patch to try to confirm what is happening and whether the patch works.
Comment #5
yched commentedLook closer :-)
(below is copy / paste from nedjo's comment #5 in the post you mention)
the 'jscalendar' class is for
$form['date'], and the '#jscalendar_ifFormat' setting is for$form.Well, it does seem couter-intuitive to me as well :-)
Comment #6
karens commentedThe patch works great, exactly as described. It correctly interprets different settings on a per-widget basis instead of form-wide.
Comment #7
nedjoApplied, thanks yched for the patch and Karen for the review.
Comment #8
yched commentedThanks nedjo.
Here's the corresponding patch for README.txt
It seems you applied that to the HEAD branch. Maybe you could also apply it to 4.7 as well ?
Comment #9
yched commentedstatus for the README patch...
Comment #10
nedjoThanks, applied the changes to the readme and applied the patches also to 4.7.
Any further improvements you might want to contribute would be very welcome!
Comment #11
binford2k commentedThis does not appear to be working correctly. This is what I have in my module:
and this is what appears in the HTML output:
In an entirely different part of the form, this appears:
In the jscalendar.js file, it looks to me as if it's looking for an id of
edit-startdate_jscalendar-ifFormat, notedit-ifFormat.I just downloaded jstools-cvs and updated Drupal core to the latest tarball today.
Am I missing something?
Comment #12
yched commented@binford2k :
are you using drupal 4.7 or drupal HEAD (5.0) ?
I think Jstools-cvs is for HEAD.
With drupal 4.7 you should use http://ftp.osuosl.org/pub/drupal/files/projects/jstools-4.7.0.tar.gz
(listed in the "other releases" section on the jstools project page.
@nedjo : maybe it would be best if the "default" download package on the project page was 4.7 instead of HEAD ?
Comment #13
karens commentedI think it will work if you add '#tree' => true to your form array.
Comment #14
binford2k commented@yched: I tried 4.7.0 and cvs and both had the same behaviour
@KarenS: '#tree' => true had no effect.
What should I check next?
Comment #15
karens commentedWhere did you put tree=>true? It needs to be under 'startdate', not elsewhere in the form array.
Comment #16
karens commentedOK, I can replicate this problem, too. Like you, I am getting those hidden fields with no field name in them. Initially I thought #tree was fixing it, but I guess not. I think the forms api is misunderstanding something about what should be created here but I'm not sure what else to try, either.
Comment #17
karens commentedI had that backward. #tree=>TRUE needs to be *above* the element in the array to get the hidden values to work right. That tells the forms api not to collapse the form down to the name of the last element in the array. In my tests, adding #tree->TRUE to the parent of the element I am adding jscalendar to will create the right hidden value in the form.
Don't know if that fixes the problem, but I think it will create the right hidden value in the form.
Comment #18
karens commentedOK, I can confirm that adding #tree=>TRUE to the parent of my jscalendar element fixes the problems I was having. I think we should fix the documentation to indicate that the form array must have #tree set somewhere above the jscalendar element. (I started playing around with the idea of having jscalendar.module set it when it creates the hidden field, but there are lots of ways that might break the form, so fixing the documentation is probably a better solution).
Comment #19
yched commentedThere was in fact a problem - thanks binford2k for finding this.
This patch _should_ take care of the #tree thing without messing with the form.
It seems to works on my test form, on the date.module jscal widgets (blink Karen), and on the jscal widget used by some Views filters (which currently don't use jscal options, but I tried to add some just to see...)
Could you both please test this on your own test forms ?
Patch if against 4.7.
Comment #20
yched commentedI mean "Patch IS against 4.7"...
Comment #21
karens commentedWorks fine on my test form. I didn't check the date.module forms since you said you tested them :-)
Comment #22
stefano73 commentedI made a patch for jsCalendar to make the Unix timestamp readily available when users choose a different date through the calendar. The timestamp is updated by the calendar and saved in a hidden field, and it can be read in the submit function by the $_POST variable (seems that the $form_values gets the original values for hidden fields, so the changes are available in $_POST only...).
Here I explain my changes.
In the jscalendar.module I added the "timestamp" hidden field, and set the other fileds as disabled, as the submit doesn't need them.
In the jscalendar.js I passed the timestamp field as a parameter, and added the code to fire when the calendar is updated. The cal.date.print('%s') is the unix timestamp for the chosen date.
In the form submit function the unix timestamp is available by the $_POST variable:
PS: the attached patch was made on the fly from my cvs version, hope there's no bug in it. In next follow up I'll post the cvs updated patch with the jquery code.
Comment #23
stefano73 commentedHere is the patch to make it work with latest cvs version.
Comment #24
yched commentedstefano73 : I'm sorry but unless I'm missing something, this has nothing to in this thread - please submit your patch in a separate issue. Let's not mix patches :-)
The RTBC patch for "per widget jscal settings" is in comment #19
Comment #25
binford2k commented@yched: works for me too. Thanks much!
Comment #26
nedjo@yched thanks, applied.
@stefano73: thanks for the suggested patch, please do move it to a new issue. You can just post the patch there with a quick explanation and reference this issue, e.g., "moved from http://drupal.org/project/comments/add/80746".
Comment #27
(not verified) commented