views:

37

answers:

2

Hi everyone,

Does anybody know how one would go about looping through all the elements in a form using Dojo? (the form itself was created through the ZendFW Zend_Dojo_Form)

What I'm trying to do is go through all the fields/inputs in the form, and if possible, change their id value. However, even if its not possible to change the ID's of fields I would still love to know how to loop through the form elements and access their properties/values.

Thanks!

A: 

As elements are objects it's easy:

foreach($form->getElements() as $element) {
     $element->id = 'new';
}

$form is obviously your form object from your class. Ie:

$form = new My_Form_Class;

As I said, it's an object so properties can be changed easily. var_dump an element to see what you can change if you're unsure

Ashley
Thank you for answering, but I was hoping to access the elements through javascript (so I can adjust them after the page was loaded). Any ideas?
A: 

Zend adds a variable of Dijits rendered on the page called 'zendDijits'. Iterate through that, getting the original element by id (it's the first item in the array), then using dojo set the id using:

for(var i in zendDijits) {
var theid = zendDijits[i]['id'];
dojo.byId(theid).id = 'new';
}

Never done it before but that should work

Ashley
Hmm, that's interesting, I didnt even think about that. Sounds like a nice solution, I'll have to try it out. Thanks!