How to insert style into a Zend_form_element_select element?

Asked

Viewed 135 times

7

How can I insert a style in one element option using Zend_form?

I’m using Zend Framework 1.

  • From what you see in documentation of Zend_Form_Element_Select, This should not be possible directly. You may need to assemble your options in the nail (perhaps extending a Zend class, as suggested (in English) here: http://stackoverflow.com/questions/7012943/how-could-i-add-attributes-to-ionopt-tags-using-zend-framework)

  • 1

    Remembering that only some browsers support styles in options.

  • Good observation...

  • Please post the code that generates these elements so that I look for a better solution...

1 answer

3

You can use the setAttrib to enter your attribute and value:

foreach ($this->getElements() as $element) {
      $element->setAttrib('class', $minhaClasse);
}

More about, here.

  • Kenny, for each option will be assigned a different color that will come from an sql, in this your example, putting in a foreach at the time of insertion of the option, will work?

  • Yes, I edited the answer to how you can do it!

  • Kenny, for this your solution the class is inserted in the select element and not in the option. : ( what I need is an alternative to color each option with different colors, maybe even insert a span within the option with the style or class due.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.