0

I have created a fieldset (which groups a field collection). Because it has a few nested levels and many fields, I want it to be shown collapsed. I am trying this code but it does not work. The id is retrieved directly from the source code of the web browser. The fieldset is the top-level, and there are more fieldsets inside of it. The form is displayed in the Admin page, the node edit form. The field "field-seo-general" is a #container.

function hook_form_alter(&$form, &$form_state, $form_id){
    if($form_id == "my_form"){
        $form["field-seo-general"]['options']['attributes']["#collapsible"] = TRUE;
        $form["field-seo-general"]['options']['attributes']["#collapsed"] = TRUE;
      ...
} // function
  • I don't have time to test this out myself, but try adding the classes "collapsible" and "collapsed" to your field_seo_general field. so something like $form['field_seo_general']['attributes']['class'][] = 'collapsible'; etc. Edit: If that doesn't work, try taking out ['options']['attributes'] in each line. – Erin McLaughlin Oct 29 '15 at 18:04
  • Thanks, I have solved at high level with module Field Collection Fieldset. – Cesar Oct 29 '15 at 18:13
  • I tested by removing options and attributes. I will try later your option and compare with what the module does. – Cesar Oct 29 '15 at 18:15
0

I have solved it installing the module Field Collection Fieldset, and instead of Embedding the Field Collection, I have put it as a Fieldset, and then one of the options is to be shown Collapsed at rendering. All with a module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.