Closed (fixed)
Project:
Content Taxonomy
Version:
6.x-1.0-beta1
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
8 Aug 2008 at 03:29 UTC
Updated:
25 Aug 2008 at 08:34 UTC
is it possible to alter the option values for checkboxes before the form is rendered?
with hook_form_alter, I used devel's dsm() to print the $form object.
I can see my instance of a cck taxonomy field, but i can't see the options.
can i manipulate them somehow?
I would like to alter which terms display depending on the default value of another form field.
thanks
Comments
Comment #1
mh86 commentedHi!
I would have expected the options being available in hook_form_alter() too...
I've to take a closer look at this.
Comment #2
mh86 commentedcontent taxonomy is using the option_widgets element of CCK. The elements are having an #process function to generate the options and other settings.
It seems like, that this #process function gets called after hook_form_alter().
At the moment I see two ways in altering the #options: either using #after_build or #pre_render.
This would look something like this:
Instead of #after_build and #pre_render I should be possible to add an additional #process too, but I didn't try out.
I hope this information helps you. It seems to be a bit more complicated as in D5.
Comment #3
loze commentedThank you, this helped greatly.
I ended up using #after_build
In doing this I also discovered that, for checkboxes, the values are in there twice (still not sure why, but select lists don't have this)
each option was listed as an array as $form['my_field']['value'][tid]
as well as key/values in $form['my_field']['value']['#options']
in my case i was simply removing some values based on another form value
so i had to loop through these and unset where appropriate.
it seems to work.
thanks!
Comment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.