I was trying to make a file type element appear/disappear when a checkbox was checked or not.
When i added the ‘#states’ declaration in ‘myfile’ element it didn’t work as expected!
I had to add the ‘myfile’ element in a ‘container’ type element and add to that the ‘#states’ declaration.
'#type' => 'checkbox',
'#title' => t('Yes i want to upload a file'),
);
$form['upload_container'] = array(
'#type' => 'container',
'#states' => array(
"visible" => array(
"input[name='want_to_upload']" => array("checked" => TRUE)),
),
);
$form['upload_container']['myfile'] = array(
'#type' => 'file',
'#title' => t('Choose your file'),
'#description' => t('You are allow to upload jpg, jpeg, png, gif and pdf, 5MB Max Size'),
);