How to manage dynamic lines coming from a form in a controller

I have a form that submits a dynamic number of rows and columns. Here's a demo on jsFiddle of what the form looks like.

I have columns of red, yellow and green, and there may be a dynamic number of rows associated with those shades of colors. Each line has a text box and checkboxes.

How can I keep track of what has been selected by the user in my save()

action controller ?

For example, for the following screenshot from the form

enter image description here

I am getting the following response back to the controller:

[red:on, green:[on, on], shade:[light, dark, , ], action:save]

      

Question

Now the problem is that although I have all the shades that the user entered, I have no way of plugging back in which rows the checkboxes were checked for the different color columns.

I am interested to know how to do this in Grails / Rails or other frameworks.

+3


source to share


1 answer


So, you need to increase your names:

<input type="checkbox" name="red.1" />
<input type="checkbox" name="red.2" />
<input type="checkbox" name="red.3" />

      



Then you can iterate over them like so:

params.list("red").each {
}

      

0


source







All Articles