Is it possible to put the results of a view into optgroups for a cck nodereference select field?

I am able to get the data from views. However even if i set 'group fields', it populates the select field with a flat list, even though my views preview properly groups them.

Is optgroups with nodereference possible or am i just doing it wrong?

thanks

Comments

loze’s picture

Anyone do this before?

Anonymous’s picture

Subscribing...

tmsimont’s picture

subscribe

antiorario’s picture

It seems this still hasn't been solved. I opened a feature request in the CCK issue queue: #1045326: Make grouped records show up as optgroups.

daigo75’s picture

I discussed the issue today, and I couldn't find a solution by using CCK alone, so I coded my own method by using hook_form_alter.
Drupal allows to create items in Select Widgets by passing an array of arrays:

my_items['group'] = array('key1' => 'value1', 'key2' => 'value2'); // etc
my_items['group2'] = array('key1' => 'value1', 'key2' => 'value2'); // etc

I therefore added a hook_form_alter function where I process the Option List contained in the Select Field I'm interested into, and I re-format it by adding the Groups. It's a bit of a hack (first attempt), but it works reasonably well.

For more information, see http://www.drupalcenter.de/node/21463 (in German, but the code is quite clear).