How to loop through form elements/fields with Dojo
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, ch开发者_高级运维ange 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!
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
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
精彩评论