PDA

View Full Version : .setValues for array form fields



willjohnathan
2 Nov 2011, 11:07 AM
I have a large form that allows users to save to and open from a database. When loading data from the database I am using the setValues method (see code below) that way I can reference each input by its name. This is working fine until I get to inputs on the form that I have set as an array. Is there a simple way to load these values using this same method. I am thinking of just giving these inputs an id and referencing them by id during the load process, but I would prefer to not have to do that for every time I have a form that uses arrays.

This does not work


formName.getForm().setValues({
field_a : value_a,
field_b : value_b,
field_c[0] : value_c[0],
field_c[1] : value_c[1]
});

Any Suggestions?

mitchellsimoens
18 Nov 2011, 11:10 AM
id is not a good idea for production. If setValues don't fit your needs, iterate through the items and set the value on each field but this way you can add some logic, that's what setValues does.