Having three fields on a form: year-from, year-to and a title, all textfields. The title field should be enabled if and only if either of the year fields is filled, and having considered that Form API's #disabled attribute cannot be used for this. So I've came up with this:
function mymodule_myform() {
$form = array();
$form['yearfrom'] = array(
'#type' => 'textfield',
'#title' => t('Year from'),
);
$form['yearto'] = array(
'#type' => 'textfield',
'#title' => t('Year to'),
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#states' => array(
'enabled' => array(
'#edit-yearfrom' => array('filled' => TRUE),
'#edit-yearto' => array('filled' => TRUE),
),
'disabled' => array(
'#edit-yearfrom' => array('empty' => TRUE),
'#edit-yearto' => array('empty' => TRUE),
),
),
);
}
This ensures that the form comes up with all the three fields being empty, and the title field being disabled (by jQuery, only on client-side). This ensures that when either of the year fields has anything in it, the title field becomes enabled. Speaking CS: both the enabler and disabler conditions are OR'ed together, but the disabler ones should be AND'ed.