Hi , im very new on drupal but im trying to alter a form that is already working. i have this form with a list of question and im trying to make one of this invisible if the result of a table is empty. i have to make invisible more than 20 question at time. here some code so you can have more clear what im saying

$form['documentation']['9'] = array(
'#type' => 'radios',
'#title' => t('Any question?'),
'#options' => drupal_map_assoc($YesNoOptions),
'#required' => FALSE,
'#group' => 'documentation',
'#states' => array(
'invisible' => array(
),':input[name="14A"]'=> array('filled' => false),
),

);

$activities = _ajbeneficiaryprofile($uuid);

$rows = array();
foreach ($activities as $activity) {
$rows[$activity->entity_id] = array(
'program_name' => $activity->field_program,
);
};

$form['programs']['program_info']['14A'] = array(
'#markup' => theme('table', array(
'header' => array('Programs'),
'rows' => $rows,
'empty' => 'Doesnt have any program',
'attributes' => array('style' => 'width: 70%'))));

Any idea? i know that this could be simple but i dont know how to solve

Thanks

Comments

Dirst’s picture

Hi.
Here is the example on how to use states property on the forms in Drupal 7

///checkbox controls other elements  
$form['check'] = [
      '#type' => 'checkbox',
      '#default_value' => 1,
      '#title' => t("check"),
  ];
  
///states assigned for controlled elements
  $form['contain'] = [
      '#type' => 'container',
      '#states' => [
        'visible' => [
          ':input[name="sellback"]' => array('checked' => TRUE), ///If you want invisible on CHEKED, just change checked to FALSE
        ],
      ],
  ];
Mistique’s picture

Hi Dirst i understand what you say but the problem here is that i dont know how to set de invisible property to a table element. I know how i can do it , to a select or a checkbox , the problem is when i want to do it with the result on a table if is empty or not

Dirst’s picture

Im not sure if I understand what are you trying to do. Are you trying to hide particluar row in the table by checking/unchecking checkboxes?