When you make a select list on a webform module you get the option to group values by a group name or category:

"Option groups for lists and menus may be specified with . <> can be used to insert items at the root of the menu after specifying a group."

Is this something I can do with CCK select fields? I have never heard of it but it would be nice.

I have to make a list of working group positions on my site and I have 3 groups each with it's own group name, Standing Task group, Sub Teams and management and I am trying to figure out the best way to list these groups and their positions in a nice select value widget.....

I was thinking of using taxonomy but it's not really the same thing as what I want.

Becky

Comments

markus_petrux’s picture

Status: Active » Fixed

Support for optgroups was recently added to CCK. However, you need to provide the list of allowed values using PHP code.

Example:

return array(
  'OptGroup A' => array(
    1 => 'Option 1',
    2 => 'Option 2',
  ),
  'OptGroup B' => array(
    3 => 'Option 3',
    4 => 'Option 4',
  ),
  'OptGroup C' => array(
    5 => 'Option 5',
    6 => 'Option 6',
    7 => 'Option 7',
  ),
);

Of course, this structure can come from a Content Taxonomy widget, for example.

beckyjohnson’s picture

Oh awesome. Thanks. I don't know why I couldn't find the documentation for it earlier.

Thanks!

Becky

beckyjohnson’s picture

I did some research and it looks like this only works with 6.x-2 dev. Is that correct? I put the php code in my cck widget in the php section and it did not work. I am using 6.x2.5.

Becky

markus_petrux’s picture

You should put this PHP code in the proper textarea of the Allowed Values list section of the field settings. This is for Text or Number fields with select widget.

IIRC correctly, support for optgroups is present in CCK 6.x-2.5 already. See release notes or CHANGELOG.txt.

beckyjohnson’s picture

Hmmmmm Ok. I put my code in the php text area of the allowed values list section and when i went to create content, none of the options were present..... I will take another look.

Thanks,

Becky

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

francesco81rs’s picture

Status: Closed (fixed) » Active

Sorry, I do not know if I'm posting correctly.
But I wanted to ask if it is possible translate single items.

For example:

return array(
  'OptGroup A' => array(
    1 => t('Option 1'),
    2 => t('Option 2')
  )
);

This doesn't work for me.
Thanks for the help.

Francesco.

Rishi Kulshreshtha’s picture

Title: Select fields with group names? » What if we want this for Drupal 7?
Priority: Normal » Critical
Issue tags: +select list, +drupal 7, +optgroup

I'm having the same problem as mentioned by beckyjohnson, but I'm using Drupal 7, is it possible in Drupal 7 to have group names in select list? If yes, they please mention how can we achieve it.

Thanks in advance!

Rishi Kulshreshtha’s picture

Title: What if we want this for Drupal 7? » Select fields with group names?

I've gone through this post also http://fourkitchens.com/blog/2010/11/09/option-groups-drupal-forms, though it meets the requirement but as a new developer to Drupal, I didn't got all the points clearly in terms of how to apply that or how can we achieve that?

Can someone just help us out in getting the solution for this one or the above one.

Thanks in advance!

marcvangend’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)

@RishiKulshreshtha the issue for Drupal 7 is #1012640: Support grouping in allowed values for select list. Also note that the 'critical' priority is reserved for bugs (not support requests and feature requests) that completely break an entire site.