Hi!

I use the options widget for displaying an admin form for mapping roles from an external system to the drupal roles.

This means I save an array with the drupal role ids as key and the role name in the external system as value.

e.g:

| Key (Drupal Role ID) | Value (External Role Name) |
| 9                    | ROLE_DIRECTOR              |
...

This is not very helpfull, at the moment I display the roles and the role ids above the widget. So the admin knows which id is which role.
Is it possible to add an optional description column to the widget which can be displayed instead of the key values? So I could display the drupal role names and let the admin enter the values easily by reading the key column description.

Regards
marcus

Comments

quicksketch’s picture

Drupal 7 now has support for descriptions on individual checkboxes or radio buttons, but finding a syntax and UI that is logical for this functionality is difficult. In any case, whichever module you're using to create your checkboxes will need to support storing descriptions for checkboxes/radios also, which currently isn't the case for Field module or Webform.

Open Social’s picture

Any update on this? I am also interested in adding an extra description to each option. I know this is possible for a single on/off checkbox or radio button via a simple form_alter. But I can't find this for a multiple checkboxes widget.

Edit: was not able to do this via hook_form_alter, but it is indeed possible via theme_preprocess_form_element().

quicksketch’s picture

Edit: was not able to do this via hook_form_alter, but it is indeed possible via theme_preprocess_form_element().

In form_alter(), it is possible but it's a little difficult:

$form['options'] = array(
  '#type' => 'radios',
  '#options' => array(
    'one' => 'One',
    'two' => 'Two',
    'three' => 'Three',
  ),
);
$form['options']['one']['#description'] = t('Description for one');
$form['options']['two']['#description'] = t('Description for two');
$form['options']['three']['#description'] = t('Description for three');

But like I said above, no module currently supports adding descriptions to checkboxes/radio buttons (neither Field, nor CCK, nor Webform). I think a larger problem yet is figuring out a UI that would be appropriate for descriptions. I don't think just adding another field would be suitable, because then you'd end up with a sea of textfields between key, label, and description.

quicksketch’s picture

Hm, I realize re-reading this request that I misinterpreted it. I thought the request was to add support for "description" in addition to "key" and "value" columns. But the request was actually to set the labels for the "key" and "value" columns. I was thrown off by calling it descriptions, when we'd normally refer to these as labels (or table headers in this case). The original request is actually quite a bit simpler and possible to implement.

hass’s picture

I need descriptions, too. Highly important feature...

hass’s picture

I need descriptions, too. Highly important feature...

dkh’s picture

Issue summary: View changes

This would be cool to add.

There is a programatic solution for adding checkbox descriptions:

$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#title' => 'Checkboxes',
'#options' => array(
'foo' => 'Foo',
'bar' => 'Bar',
);
$form['checkboxes']['foo']['#description'] = 'description for the foo checkbox';

But changing the checkbox descriptions is not something that should require a code change. There should be a way for the client to change these in the GUI with content type edit permissions.