3

I have a relatively simple webform, with 2 fieldsets and a few other fields. The fields aformentionned have #states actions configured and behaving proper like in a regular form.

It is in the fieldset shown below I have a problem. THe fieldset should be collapsed (via #states) and there is nothing I can do to make it so.

enter image description here

The offending fieldset has #states defined in the bottom form_alter, I outlined the error location in caps:

// Implements hook_form_alter()
function formHelper_form_alter(&$form, $form_state, $form_id)  {            
switch ($form_id)  {

        case 'webform_client_form_1':

           // Set fieldsets as collapsible
          $form['submitted']['inscription']['#collapsible'] = true;
          $form['submitted']['inscription']['#collapsed'] = true;              

          $form['submitted']['inscription']['enfant_1']['#collapsible'] = true;
          $form['submitted']['inscription']['enfant_1']['#collapsed'] = false;

          $form['submitted']['inscription']['enfant_2']['#collapsible'] = true;
          $form['submitted']['inscription']['enfant_2']['#collapsed'] = true;             

            //vardump of fieldset
           dpm($form['submitted']);

           // Show datepicker for child one if inscription is part time
           $form['submitted']['inscription']['enfant_1']['jrs_semaine']['#states'] = array(
              'visible' => array(   // action to take.
                ':input[name="submitted[inscription][enfant_1][horaire]"]' =>
                  array('value' => 't_partiel'),
              ),   
           );
           // Show datepicker for child two if inscription is part time  
           $form['submitted']['inscription']['enfant_2']['jrs_semaine2']['#states'] = array(
              'visible' => array(   // action to take.
                ':input[name="submitted[inscription][enfant_2][horaire_2]"]' =>
                  array('value' => 't_partiel'),
              ),   
           );
            // THIS IS THE FIELDSETY THST DOES NOT WORK: 
           // set state on second fieldset to be visible only when two is seiected.       
           $form['submitted']['inscription']['enfant_2']['#states'] = array(
              'expand' => array(   // action to take.
                ':input[name="submitted[inscription][enfant_1][horaire]"]' =>
               array('value' => 't_partiel'),
              ),   
           );
          break;
 }
}

Now, in the drupal docs (example module) there is a fieldset shown with working code using as the state to change, and it seems in the docs fieldsets are clearly supported, alas not the one in my webform.

I am using the same condition that is working on the other field so I assume the problem is not with the selector. In light of this fact, I have no clue of what even to really look for but I really want to figure it out.

Is anyone familiar enough with #states to tell me how I could debug the js in this case?

I know it is in /misc/states.js, I just don't know what to look for in states.js, or even if this is what is preventing the fieldset from collapsing.

update: Reposted the full hook_form_alter function as per request.

2
  • 1
    input[name="submitted[inscription][nombre_denfants][horaire_2]"]"] looks strange: "] is duplicated
    – Attiks
    Apr 26 '12 at 14:03
  • @Attiks yes thanks for catching that. All typos are fixed yet still #states is not firing for fieldsets. Will be looking into the JS side of this if I have the chance today, thanks! Apr 27 '12 at 5:30
1

Can you add the full code for both form items?

If the element needs to be collapsed at start-up you need to add '#collapsed' => TRUE,

It also looks like there's an error in you're selector as pointed out in comments

4
  • I added the settings to adjust the #collapsed tag as per your suggestion, but this still did not work out. I believe this same effect could also be done with simple jquery, since it is only a presentational change, but I would of liked to know why #states was choking on this. Apr 27 '12 at 5:40
  • * Also, I added the whole form_alter, as you can see I used the same selector as I did in the 2 widgets. Apr 27 '12 at 5:43
  • It needs to be "expanded" not "expand"
    – TCLopez
    Apr 27 '12 at 12:41
  • yes I tried all, visible, expanded, neither has worked for this. I had this up and working in 5 mins. with JQuery instead, but will go back when time allows and trace why it was not working with #states. Apr 27 '12 at 23:11

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.