Hi There,
I want to use dependant text field with checkbox in drupal form.
I am using form #states with required, but form gets submitted without validating the text field.
Please check below code.
$form['dummy_checkbox'] = array(
'#type' => 'checkbox',
'#title' => t('Dummy Checkbox'),
);
$form['dummy_checkbox_value'] = array(
'#type' => 'textfield',
'#title' => t('Dummy Checkbox Value'),
'#states' => array(
'visible' => array(
':input[name="dummy_checkbox"]' => array('checked' => TRUE)
),
'required' => array(
':input[name="dummy_checkbox"]' => array('checked' => TRUE)
),
)
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
Note : I have option to write validate function, but my checkbox and text field are multiple. So I need to work with #states only.