Using addMultiOption($value,$label) I just set the value parameter to something like:
$value = $id . '" ref="' . $ref;
and when it renders you get:
<option value="<idValue>" ref="<refValue"><labelValue></option>
Hope this helps....
Okay, value gets escaped but optionClasses does not so inside the loop that adds the addMultiOptions(val,lable) I do something like this:
$optionClasses[<val>] = 'ref_' . <val> . '" ref="' . <ref>;
and then after the loop just do a setAttrib('optionClasses',$optionClasses)
And that actually works...
So here is an example where I will define an array that might be a recordset from a db query with the three parts we are going to use; id, code and offset
$records = array( array('id' => 1, 'code' => 'Code 1', 'offset' => 4),
array('id' => 2, 'code' => 'Code 2', 'offset' => 5),
array('id' => 3, 'code' => 'Code 3', 'offset' => 6)
);
and I will use this in a form element definition ( in a class that extends Zend_Form) for a select where the options have an attribute called 'offset' that will have the 'offset' value from the array
$e = $this->createElement('select', 'code_id');
$e->setLabel('Event Type:')
->setAttrib('size', 1);
$optionClasses = array();
foreach ($records as $record) {
$optionClass = 'xcode_' . $record['id'] . '" xoffset="' . $record['offset'];
$optionClasses[$record['id']] = $optionClass;
$e->addMultiOption($record['id'],$record['code']);
}
$e->setAttrib('optionClasses', $optionClasses);
$this->addElement($e);
and when this is rendered, it produces a select element like
<select name="code_id" id="code_id">
<option value="1" class="xcode_1" xoffset="4" selected="selected">Code 1</option>
<option value="2" class="xcode_2" xoffset="5">Code 2</option>
<option value="3" class="xcode_3" xoffset="6">Code 3</option>
</select>
and then you can get to the offset of the selected option with jQuery using
var xoffset = $("#code_id").find("option:selected").attr("xoffset");
this works because the optionClasses resulting class attribute does not get escaped by the rendering method like the value attribute does.