jquery dynamic form elements for spring form binding

2k views Asked by At

I am facing issues with dynamically binding spring form elements in JSP using jquery. I am trying to add dynamic rows to a table which has different form elements. Demo: http://jsfiddle.net/ninadhere/f7ZdK/

Issue here is newly added form elements are havng id's & name attribute as "userName[0]1" instead of "userName[1]" hence they are not getting binded to spring form. I am using a AbstractWizardController and trying to binding Dynamic list of User's on Step1 and then using them in Step2.

Is their a way to systematically clone the form elements like dropdown, checkbox and text.

Can someone guide me on using this correctly.

2

There are 2 answers

2
Anoop On BEST ANSWER

pass true while cloning the element will copy all event with the cloned element.

from http://api.jquery.com/clone/

.clone( [withDataAndEvents] ) withDataAndEventsA Boolean indicating whether event handlers should be copied along with the elements. As of jQuery 1.4, element data will be copied as well.

Replacing integer value of id:

  id.replace(/\[\d*\]$/, "["+ i +"]")// will replace 'userName[0]' with userName[{i}]
2
Japan Trivedi On

I have performed things like this before its quite tricky and you need to have full concentration while binding dynamic form field to the spring model.

Please refer this link

Though my question is different but the code I have put in the question is what probably your answer. :)

Hope this helps you.