Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As I see the checkbox elements' customization possibility is undocumented in form API reference. To be more specific take a look to the following example:
$form['myboxes'] = array(
'#type' => 'checkboxes',
'#options' => array(
'foo' => t('Foo'),
'bar' => t('Bar'),
'baz' => t('Baz'),
),
);
$form['myboxes']['foo'] = array(
'#attributes' => array('class' => array('ok')),
);
$form['myboxes']['bar'] = array(
'#disabled' => TRUE,
);
The above snippet is from here and it actually works I tested it. However if I'am not wrong it is still not documented.
Please document the above mentioned behavior on the Form API Reference page.
Comments
Comment #1
balazswmann CreditAttribution: balazswmann commentedComment #2
jhodgdonThe #default, #options, and #attributes properties are all actually documented. You just have to click on the links at the top of the checkboxes section. I don't think there is any missing documentation. Please open this issue back up if you think there is.
Also I've moved this to the Documentation project because the file for that page is in that repository, not in Core.
Comment #3
balazswmann CreditAttribution: balazswmann commentedThanks for the project related changes, however I still think that the mentioned behavior of the checkboxes form element is not documented.
That is correct that attributes (like #default_value, #options, #attributes, etc.) are documented both at the checkbox element and at the checkboxes element, but if you are using the checkboxes element it is not documented how you can customize the attributes of it's checkbox elements. You can specify each checkbox element's key and value in the checkboxes element's #options property as you can read in the checkboxes element's description section, but you are not informed about how you can customize other checkbox properties apart from their key and value. So this is what I wanted to point out since this is a really important behavior. Without this information developers are not able to customize checkbox elements' properties inside a checkboxes form element, or they have to use different "dirty tricks" (like #process, #after_build, etc..) to accomplish the same behavior meanwhile there is this "simple and clean" but undocumented solution.
Comment #4
jhodgdonAh, OK. Thanks for writing down what you think needs to be documented. Sounds like a reasonable thing to document. I didn't understand what you were talking about from your original issue report.
Comment #5
jhodgdonI believe this is a duplicate of #1349432: Mention checkboxes/radios options pre-setting in forms_api_reference.html