Go To Content
codylindley.com

codylindley.com

Duplicate Form Inputs

Not long ago, I dreaded the thought of having to code the JavaScript functionality that would allow a user to add duplicate form inputs. But with a little help from jQuery, this type of functionality went from visual design to functional prototype with ease. Boy, that just sounded like an infomercial – good thing jQuery is free.

I rarely see such an interface discussed, and in case you haven’t looked, it’s quite difficult to find a good code example for this pattern. Then again, it is a rather complex and highly custom functionality dependent upon the interface and user goals.

At any rate, check it out. Feedback welcomed.

 
  1.   #1 Comment Posted by Nathan Logan on Apr 24, 10:24 AM

    Nicely done. Per usual.

  2.   #2 Comment Posted by Jonathan Snook on Apr 24, 10:44 AM

    There’s a bug whereby if you create a couple and then delete one in the middle, you can add one more but no more after that.

    After duplicating a set, the user should be able to delete the first set. I know why you’ve done it the way you have but if you can delete any of the others, why not the first?

    Otherwise, it’s looking pretty good.

  3.   #3 Comment Posted by Aaron Berk on Apr 24, 11:49 AM

    I like the interaction. I did a similar pattern, but it was a pain in my butt! It was fun to work on though. I was still a bit new to Front End, so the underlying code may not be that great, but I was proud of the end result. I’d love to revisit it and update it with something a little more up to date. Maybe this will be my motivation. Funny enough, I apparently used jQuery and also Jonathan’s getElementByClassName code.

    http://images3.ichotelsgroup.com/flash/html/meetings/budget/index.html

  4.   #4 Comment Posted by matthijs on Apr 26, 01:35 AM

    Looks great. Only question I would have is how to keep the data input you already entered. I imagine that someone fills in a few rows and then decides to add one more. In the current script you loose your data when you click to add another row.

  5.   #5 Author Comment on Apr 26, 08:34 AM

    @matthijs – I’m not sure what you mean. Right now the fields are not really usable because I am using them to output the name of the field. I change this, and now input data should stick. This really was not a bug, just a way to demonstrate that each input will have a unique name.

  6.   #6 Comment Posted by matthijs on Apr 27, 02:40 PM

    Cody, now I see why that was. Thanks for clearing that up.