1

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.

Ninad
  • 53
  • 7

2 Answers2

1

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}]
Anoop
  • 23,044
  • 10
  • 62
  • 76
  • well here i dont need to copy element data i want to make sure the secure of dynamic form elements is generated correctly right now when I clone its get clone as **** instead of **** – Ninad Oct 10 '12 at 22:32
  • Thanks Shusl seems to work fine. Live Demo: http://jsfiddle.net/ninadhere/f7ZdK/5/ – Ninad Oct 11 '12 at 15:24
0

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.

Community
  • 1
  • 1
Japan Trivedi
  • 4,445
  • 2
  • 23
  • 44