Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created July 16, 2012 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikwattro/3122080 to your computer and use it in GitHub Desktop.
Save ikwattro/3122080 to your computer and use it in GitHub Desktop.
protoype field
function addFieldForm(collectionHolder, $newLinkLi)
{
var prototype = collectionHolder.attr('data-prototype');
var newForm = prototype.replace(/__name__/g, collectionHolder.children().length);
var $newFormLi = jQuery('<li></li>').append(newForm);
$newLinkLi.before($newFormLi);
}
var collectionHolder = jQuery('#unimog_contenttype_fieldbundle_contenttypetype_fields');
var $addFieldLink = jQuery('<a href="#" class="add_field_link">Add a field</a>');
var $newLinkLi = jQuery('<li></li>').append($addFieldLink);
jQuery(document).ready(function()
{
collectionHolder.append($newLinkLi);
$addFieldLink.on('click', function(e){
e.preventDefault();
addFieldForm(collectionHolder, $newLinkLi)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment