Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to make some date fields appear if a dropdown above it says 'on leave'- is this possible?
Cheers,
Chris.
Comment | File | Size | Author |
---|---|---|---|
#17 | 808658.ctools.date-dependency-docs.patch | 2.18 KB | joachim |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedI'm afraid I don't understand the question or the context of the question.
Comment #2
chrism2671 CreditAttribution: chrism2671 commentedSorry merlin, I was referring to the function described on the Ctools homepage as "Dependent -- a simple form widget to make form items appear and disappear based upon the selections in another item."
I took a look at dependent.inc but it only refers to checkboxes/radios. I was hoping to do the same with date & select. Is this possible?
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedAh! Yes you can make any field dependent on a dropdown; checkboxes and radios need special handling, is all. Views does it with textfields all over the place (it uses its own version of the same code).
Comment #4
chrism2671 CreditAttribution: chrism2671 commentedBrilliant thanks!
Just trying to get this to work, does this make sense to you?
I think my problem lies in the #dependency- I'm not sure if my syntax is quite right. It's based on '#dependency' => array('id-of-form-without-the-#' => array(list, of, values, that, make, this, gadget, visible))
Any help much appreciated! Thanks! :-)
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedOnly radios use the special 'radio:' notation. You want to just use the id of the select which would be
'#dependency' => array('edit-personal-rfxuser-work-status' => array(2)),
(probably best to compare against the id in firebug of course)
Comment #6
chrism2671 CreditAttribution: chrism2671 commentedOK great- I've got it working using textfields, BUT, it appears to fail on date fields. I think this might be because a date field actually consists of three selects with different id's (month, day, year). Interestingly, these get blocked at the PHP level, i.e. the date field doesn't get written to the page at all, so the JS has nothing to hide.
I had a good go at debugging dependent.inc but had no joy- what do you think?
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedOh it may just be about ids. It's possible that date fields have the same problem that checkboxes and radios have, that Drupal doesn't provide the wrapper ID? Check the HTML source (compare to the textfield you've got working) and see. Sometimes just using #prefix and #suffix to provide the right #id will work.
Comment #8
chrism2671 CreditAttribution: chrism2671 commentedOk cool, I'm at the airport heading to turkey but I'll check it when I return! :-) thanks for all the help! :-)
Comment #9
perusio CreditAttribution: perusio commentedI'm trying to get it to work in a ctools modal. It's for some style settings in a panels everywhere theme. Here's my code:
I've checked with the browser inspector in chromium and everything it's ok, related to CSS IDs and such. But the radios never expand. I might add that this is a simplification of a previous situation with checkboxes. I tried this single checkbox, but to no avail. Any help is much appreciated.
Thank you
Comment #10
perusio CreditAttribution: perusio commentedOk. I grokked it. Between the HTML elements view and the console of the chromium browser inspector I managed to figure it out by inspecting the Drupal.CTools.dependent object in the console.
Here's my code. I want the hidden element to show if any of the checkboxes is selected.
This is much nicer than the FAPI ahah form framework for this type of action. Merlin would an example module for dependent.inc interest you for inclusion in CTools? Right now there's a example plugin module, IMHO, there should be more examples of usage if the tools.
Of course I can always add a documentation page at d.o and include the example code.
Thank you for CTools.
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedYes, yes, and more yes. Absolutely. Documentation is one place where people can really help improve CTools, because it's a place where I've been very poor at focusing my time.
Comment #12
merlinofchaos CreditAttribution: merlinofchaos commentedMarking fixed, the answer has been posted.
If anyone who participated in this would like to help improve the documentation, that would be greatly appreciated.
Comment #14
adf1969 CreditAttribution: adf1969 commentedA note for anyone who has issues getting the ctools_dependent_process to work with date_popup widgets.
I ran into the same problem as chrism2671. It would display the date labels, but the date fields didn't display at all. (although the "dependent" functionality worked just fine, it just worked *only* with the labels since the date input elements did not get sent to the page)
I found out (by stepping thru the code numerous times) that I had to add a "date_popup_process" as indicated below. Then it works fine.
The following is the code I am using.
Hope this helps save someone else some time...
Andrew.
Comment #15
sepla CreditAttribution: sepla commentedIf you're making a date field dependent make sure that you're not removing
expand_date
callback by overwriting the#process
array. Below is a working example of a checkbox dependent date field:Comment #16
joachim CreditAttribution: joachim commentedAddendum to #15: depending on what type of date field you have (popup, select, etc) the process item is different, eg for a popup:
The code in _date_api_elements() shows which one to use.
Comment #17
joachim CreditAttribution: joachim commentedHere's a patch with that information.
Comment #18
japerryClosing this issue as outdated as Drupal 6 ctools is not supported. If this issue is relevant for Drupal 7, feel free to re-open and mark for Drupal 7 (or 8)