Created
April 2, 2013 14:37
-
-
Save aviflombaum/5292703 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('form a.add_child').click(function() { | |
| // The link that was clicked on has a data-association attribute that points it to the correct ID to clone. | |
| var association = $(this).attr('data-association'); | |
| // Grab the template of the fields you want to copy, convert it to a string via the html() method | |
| var template = $('#' + association + '_fields_template').html(); | |
| // Create a random number to replace the ID / name | |
| var regexp = new RegExp('new_' + association, 'g'); | |
| var new_id = new Date().getTime(); | |
| // Replace and Insert | |
| $(this).parent().before(template.replace(regexp, new_id)); | |
| return false; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment