0

I got a problem to toggle the textfield if the ckeckbox with value 1 is checked.

function gkform_nameform() {
 $form['check'] = array
    (
    '#type'            => 'checkboxes', 
    '#options'         => array
      (
      1 => 'Sometext',
      2 => 'Sometext2',
      ),
    );
$form['user_name'] = array(
'#type'=>'textfield',
'#states'=>array(
    'visible'=>array(
    ':input[name="check"]'=>array('checked'=> 'options' => '1' == TRUE),
    ),
  ),
 );

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Download')
);
return $form;
}
3

The Form API gives checkboxes names that include their options key. So your :input needs to be slightly adjusted to

':input[name="check[1]"]' => array('checked' => TRUE),
  • is there a goog introduction into the whole thing you can recommend? Thanx a lot! – Jurudocs Nov 8 '11 at 13:59
  • @Jurudocs I like looking at the examples module for real world documentation. It has a whole form that shows how states works (including checkboxes) – rocketeerbkw Nov 8 '11 at 16:37

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.