I'm creating a form in Symfony2
, one of my fields is a collection
field & I'm using it in form like this:
{{ form_start(form) }}
{{ form_errors(form) }}
...
<div>
{{ form_label(form.tels) }}
<a href="#" id="add-another-tel">+</a>
<ul id="tels-fields-list" data-prototype="{{ form_widget(form.tels.vars.prototype)|e }}">
{% for telsField in form.tels %}
<li>
{{ form_errors(telsField) }}
{{ form_widget(telsField) }}
</li>
{% endfor %}
</ul>
<script type="text/javascript">
var telCount = '{{ form.tels|length }}';
jQuery(document).ready(function() {
jQuery('#add-another-tel').click(function(e) {
e.preventDefault();
var telsList = jQuery('#tels-fields-list');
var newWidget = telsList.attr('data-prototype');
newWidget = newWidget.replace(/__name__/g, telCount);
telCount++;
var newLi = jQuery('<li></li>').html(newWidget);
newLi.appendTo(telsList);
});
})
</script>
</div>
...
{{ form_rest(form) }}
{{ form_end(form) }}
While I'm calling {{ form_label(form.tels) }}
but at the end of the form & when {{ form_end(form) }}
is called the label of this field is printed again.
So I have two labels for this field (one at the correct position & another at the end of the form).
This occurs as many as collection fields I have.
What is the problem?