Thanks to the patch in http://drupal.org/node/970048#comment-5712492 I am able to programmatically insert an addressfield form element into a custom code using the Form API. However, applying the #states property has no effect on the element - it will always display even when it shouldn't. I know that my code is correct because I have exactly the same lines of code for applying the #states property to another element and that works as expected.
I am happy to write a patch to the patch above to enable this functionality but I am unsure how or where to start, and Googling hasn't helped. So either a bit of guidance on how form elements work with the #states property, or some existing code that someone may have written already to do this would be awesome.
Thanks.
Comments
Comment #1
caschbre commentedI've been having the same issue. I'm able to use hook_form_alter to add #states attribute to other fields, however I'm not able to with the addressfield.
@melissavdh... did you get anywhere with this?
Comment #2
caschbre commentedSo far my work-around is to use hook_form_alter to...
1) Copy the field to a variable
2) Unset the field from the $form
3) Create a fieldset element
4) Copy te variable as a child of the fieldset
5) Attach the #states on the fieldset.
Comment #3
melissavdh commentedThe only way I was able to achieve this was to put the addressfield element inside a fieldset or a container and then apply #states to that fieldset or container.
Comment #4
caschbre commentedYeah, that's the way I had to go about it.
Comment #5
rszrama commentedUpdating the title.