Closed (fixed)
Project:
Conditional Fields
Version:
6.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Jun 2009 at 00:09 UTC
Updated:
23 May 2011 at 10:41 UTC
I am trying to create a custom template for a CCK form that includes conditional fields. When I do the following in my form template:
print drupal_render($form['controlling_field']);
print drupal_render($form['controlled_field']);
The fields are both rendered just like normal CCK fields--the controlling_field doesn't actually control the visibility of the controlled_field. Is there any way to make this work? THanks for any help.
Comments
Comment #1
beauz commentedgot the same problem... any answers?
Comment #2
mrthumpz commentedI am having the same issue. I played around with the weights of the modules, but that didn't help. I can get the #conditional-fields info to show in the $form array, but the form is always rendered with all fields visible when using hook_theme() with theme_[contenttype]_node_form()
Comment #3
dinis commentedYou will need to add some logic into your output, an if statement should do.
As a precaution, make sure you save your template to disk before experimenting. If you WSOD your template, you'll have to delete it and start over :)
Hope this helps,
Dani
Comment #4
rburgundy commentedHi Dinis,
Could you please share an example of adding logic to the rendering of a field on a custom form.
Simply drupal_rendering form fields shows the conditional fields elements in devel but doesn't seem to properly show/hide the field depending on the control field.
Thank you
Comment #5
YK85 commentedsubscribing
Comment #6
peterpoe commentedI tested this using the method outlined here http://drupal.org/node/601646, and this works:
However, if you render the individual elements of the fields separately (like, say, each checkbox of field_controlled), you will have to wrap the elements in the wrapper div. You can use theme_conditional_fields_wrapper for this. An example with a checkboxes controlled field:
Note tha there is no need to alter the logic of the dependency: this only changes presentation.
Comment #7
peterpoe commentedI forgot to mention: this only applies to version 6.x-2.x
Comment #8
peterpoe commentedI added a page with this example to the documentation: http://drupal.org/node/1151380