View Full Version : 1:N Relationships in Forms

11 Jul 2010, 4:18 AM

I have a FormPanel in which the user has the possibility to add unlimited ...let's say articles for an easy example. So each time the user clicks on "add" two other form fields are created (subject and text).

When the user clicks on the finish button I want to send an array with all articles in it to the server. Is there an elegant way to do this?

My solution would be to all the fields "index-subject", so like "0-subject", "1-subject" and so on and in the finish buttton handler I collect the information like this:

var i = 0,
articles = [];
values = this.getForm().getvalues();
while(typeof values[i+'subject'] !== 'undefined') {
subject: values[i+'subject'],
text: values[i+'text']

Is there an better solution?


11 Jul 2010, 6:19 AM
another solution would be to name all the Subject fields the same and all the Text fields the same then your form submission will POST an array of the values which you can then interpret on the server.

11 Jul 2010, 12:59 PM
Does this work only with BasicForm.submit() or also with BasicForm.getValue()?
Cause I have a wizard and so I have to collect data from multiple formPanels and then combine them to one submission.


11 Jul 2010, 11:57 PM
I think you will have to do that with a function of your own to build up the parameters and post them with an AJAX request manually rather than through the form submission.

14 Jul 2010, 4:29 PM
ok, thx!