1

I am trying to realize a dynamic form with possibility to add\remove fields (just add for now cause it doesn't work). I am working with Symfony 2.0.13, and following the guide at Here but the result is that i can't obtain the

<a href="#" class="add_tag_link">Add a tag</a>

in the rendered html, as you can see Here #2

Has anyone a clue?

9
  • can you show us your javascript ? Commented May 16, 2012 at 8:38
  • It's the same from the tutorial I posted, pastebin.com/QkQSgqmZ Commented May 16, 2012 at 9:11
  • I am trying to figure out what's wrong but nothing Commented May 16, 2012 at 10:11
  • you can add the link directly to your view and just do the event on click on it that's what i did and it works like a charm ! Commented May 16, 2012 at 12:01
  • ok thanks, I'll try it, but it doesn't satisfy me because it's not meant to do this way... Adding the link directly in my view doesn't scale for N fields am I right? Commented May 16, 2012 at 13:01

1 Answer 1

1

just change the script to

jQuery(document).ready(function() {

 // Get the div that holds the collection of tags
var collectionHolder = $('ul.tags');

// setup an "add a tag" link
var $addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>');
var $newLinkLi = $('<li></li>').append($addTagLink);


    // add the "add a tag" anchor and li to the tags ul
    collectionHolder.append($newLinkLi);

    $addTagLink.on('click', function(e) {
        // prevent the link from creating a "#" on the URL
        e.preventDefault();

        // add a new tag form (see next code block)
        addTagForm(collectionHolder, $newLinkLi);
    });
});

this will work...

Sign up to request clarification or add additional context in comments.

2 Comments

need just to add the code var $newLinkLi = $('<li></li>').append($addTagLink); inside the document.ready function
You won't believe it, but I solved this problem with exactly this solution just before you posted it.... :) anyway there were also other 2 problems related with Twig that I will post when I'll have more time. Thank you for your time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.