Im using Zend, and we have a form thats put together through a series of functions. One in particular addMultiOption, of which is being pulled in from a DB (from where I dunno, cause if I could alter the query, that'd be much easier and better all around. Anyway that said I need to add a "rel" attribute to every option /option so I can preform a task on the option via jquery when that option is selected, its not all options but some, options that don't have extra functionality would have a rel of 0 where as the ones with actions will have a rel of "one" this comes from the DB so. I am trying to figure out how I can add extra attributes outside of value
does the Zend Framework support this, if not how can I achieve this? I found what I thought was a nice post here earlier about it, but turns out it just doesn't work for me
Using addMultiOption($value,$label) I just set the value parameter to something like:
and when it renders you get:
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:
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
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
and when this is rendered, it produces a select element like
and then you can get to the offset of the selected option with jQuery using
this works because the optionClasses resulting class attribute does not get escaped by the rendering method like the value attribute does.