Recently had a need for this in one of my own projects and didn't really like that the only way to achieve this was to override the theme function for the select box in question.
This patch adds a new FAPI type '#disabled_values' which would only be valid for select options. An example of using it would be as follows:
$form['test'] = array( '#type' => 'select', '#title' => 'TEST', '#options' => array('test' => 'Test', 'test1' => 'Test 1', 'test2' => 'Test 2', 'test3' => 'Test 3'), '#disabled_values' => array('test1', 'test2'), '#default_value' => 'test2' );
In the above example code, 'test2' is the default value, as well as one of the disabled options, in this case, 'test2' will actually be enabled as it needs to be a selectable option to maintain integrity of submitted data. I'm sure there are other ways to handle this, but this seems the cleanest.
PASSED: [[SimpleTest]]: [MySQL] 33,540 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 17,890 pass(es). View
FAILED: [[SimpleTest]]: [MySQL] 17,895 pass(es), 14 fail(s), and 6 exception(es). View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch form-disabled-options-284917-16.patch. View