the #option property to the #select type does not support #attributes.

Iam trying to mark some of the fields in a dropdown menu with a different color .

Anyone have a nice sollution to this?

Comments

TapocoL’s picture

If you need this to be possible, you can set select as a certain class. Then, run some jQuery (or regular Javascript) magic.

$(".selClass option:nth-child(odd)").css('background-color', '#eaeaea');

.selClass is the class that you put in the #attributes array of the select form item. This hopefully will make all odd options have a background color of #eaeaea. I have not tested this. I was just trying to give you an idea of something you could do.

-Craig Jackson
-Web Developer

olemsa’s picture

Im currently doing this for each I want to mark:

		drupal_add_js('
			$(document).ready(function(){
    $("#edit-parent > option[@value=\''.$node->nid.'\']").css(\'color\', \'red\');
  }
  );','inline');

The select list is pretty long, 200-500 fields and the jquery is to slow when searching for based on their value, how can I boost the speed?
I would like to throw away the jquery, and mark the 's with classes during form build.

matt v.’s picture

I did some quick searching and ran across a similar problem posted just a while ago. One of the responses there suggested the hook_elements function and pointed to an example in the handbook. The example presents a completely different use case, but does show how the function can be used. I haven't tried it myself, but it looks like it should work in your situation.

--
Drupal Theme Developer’s Cheat Sheet | 45 Screencasts to Get You Kicking Ass with Drupal