XZKS XZKS - 2 years ago 222
jQuery Question

Symfony2 - Collection + jQuery

I use collection type with symfony:

When I choose value in select. This value is add in list but I don't know how to make this with symfony collection.

Here my html output:

<div id="equipe_joueurs" class="mes_joueurs"
<div class="form-group">
<label class="control-label" for="equipe_joueurs___name__">__name__label__</label>
<select id="equipe_joueurs___name__" name="equipe[joueurs][__name__]" class="form-control">
<option value=""></option>
<option value="1" >Joueur1</option>
<option value="2" >Joueur2</option>
<option value="3" >Joueur3</option>

Here my js:

var container = $('#equipe_joueurs');

var index = container.find(':input').length;

var prototype = $(container.attr('data-prototype').replace(/__name__label__/g).replace(/__name__/g, index));

var prototype = $(container.attr('data-prototype').replace(/__name__label__/g).replace(/__name__/g, index));

$('#equipe_list').append('<li id="equipe_joueur_' + index + '" name="equipe[joueurs][' + index + ']">' + 'prototype.text() + '</li>');
return false;

Thanks for your help,

Answer Source


<div id="list"></div>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download