1

Basically, I need an extra bit of data to be included in a select box which is created with Zend. The current markup is as follows:

<select>
    <option label="Canadian Dollar ($)" value="1">Canadian Dollar ($)</option>
    <option label="Euro (€)" value="2">Euro (€)</option>
    <option label="US Dollar ($)" value="3">US Dollar ($)</option>
</select>

The markup I'm trying to achieve is as follows (notice the additional 'data-curreny-type' attribute):

<select>
    <option label="Canadian Dollar ($)" value="1" data-currency-code="CAD">Canadian Dollar ($)</option>
    <option label="Euro (€)" value="2" data-currency-code="EUR">Euro (€)</option>
    <option label="US Dollar ($)" value="3" data-currency-code="USD">US Dollar ($)</option>
</select>

The form is being created using Zend as follows:

$element = new Zend_Form_Element_Select(self::NAME);

/* -- OMMITED DB CODE --*/

$element->setOptions($options);

$options is an array in the form of: array('1' => 'Value1', '2'=> 'Value2').. etc.

My qestion is, is there any way of adding extra elements into the 'options' element using Zend ->setOptions($opts)? Or anything I might not be aware of.

Please help!

2 Answers 2

2

The FormSelect view helper which renders the element does not support additional attributes on the <option> tags, so the only way to achieve this would be to override that helper with your own implementation. The helper class is Zend_View_Helper_FormSelect, so if you take a look at the code for that you should be able to see how it works.

Sign up to request clarification or add additional context in comments.

Comments

0

Please use setArribute method to add an additional attribute. You can add data-currency-code as an attribute.

1 Comment

Wont' work.. because the attribs get added to the 'select' tag. I need it added to the 'options' tag. But thanks anyway. Any more suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.