Reputation: 409
I have a problem with my twig rendering for form collection on edit form. The form loads with no problems but the collection field has the label doubled and modified from option to numbers the jsfiddle will show what i mean.
Twig Template:
{% block body %}
<div class="row">
<div class="col-md-12">
<a href="#" class="add-choice btn btn-default" aria-label="Add Choice">
<span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span>
Adauga Camp
</a>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h1>Editeaza intrebarea</h1>
</div>
<div class="panel-body">
{{ form_start(edit_form, {'attr': {'class': 'form-horizontal'} } ) }}
<div class="row">
<div class="form-group">
{{ form_label(edit_form.question, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
<div class="col-md-8">
{{ form_widget(edit_form.question, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(edit_form.question) }}
</div>
</div>
</div>
<div class="row">
<div class="form-group">
{{ form_label(edit_form.surveyId, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
<div class="col-md-8">
{{ form_widget(edit_form.surveyId, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(edit_form.surveyId) }}
</div>
</div>
</div>
<div class="row">
<div class="form-group">
{{ form_label(edit_form.fieldType, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
<div class="col-md-8">
{{ form_widget(edit_form.fieldType, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(edit_form.fieldType) }}
</div>
</div>
</div>
<div class="row">
<div class="form-group">
{{ form_label(edit_form.categoryId, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
<div class="col-md-8">
{{ form_widget(edit_form.categoryId, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(edit_form.categoryId) }}
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-8">
{{ form_widget(edit_form._token, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(edit_form._token) }}
</div>
</div>
</div>
<div class="multiple-choice-prototype"
data-prototype="{{ form_widget(edit_form.answerId.vars.prototype)|e('html_attr') }}">
{{ form_widget(edit_form.answerId) }}
</div>
{{ form_widget(edit_form) }}
<div class="row">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" value="Edit" class="btn btn-default">Salveaza</button>
</div>
</div>
</div>
{{ form_end(edit_form) }}
<div class="row">
<div class="col-md-12">
<div class="btn-group">
{{ form_start(delete_form) }}
<a class="btn btn-default" href="{{ path('surveyquestion_index') }}">Inapoi</a>
<input class="btn btn-default" type="submit" value="Sterge">
{{ form_end(delete_form) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
Twig for the field:
{% block _survey_question_answerId_entry_widget %}
<div class="row multiple-choice-container">
<div class="form-group">
{{ form_label(form.value, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
<div class="col-md-8">
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-record" aria-hidden="true"></span>
</div>
{{ form_widget(form.value, {'attr': {'class': 'form-control'} } ) }}
{{ form_errors(form.value) }}
</div>
</div>
<div class="col-md-2">
<div class="btn-group">
<a href="#" class="add-choice btn btn-default" aria-label="Add Choice">
<span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<a href="#" class="remove-choice btn btn-default" aria-label="Remove Choice">
<span class="glyphicon glyphicon glyphicon-minus" aria-hidden="true"></span>
</a>
</div>
</div>
</div>
</div>
{% endblock %}
Upvotes: 3
Views: 1468
Reputation: 713
->add('answerId', CollectionType::class, [
'entry_options' => [
'label' => false,
],
'entry_type' => AnswerType::class,
'allow_add' => true,
'allow_delete' => true,
'label' => false,
'by_reference' => false,
])
This should do the job
Upvotes: 3
Reputation: 2137
Set label to false in your form type
Example :
$builder->add('yourAttribute', null, array('label' => false));
Upvotes: 0
Reputation: 2210
remove {{ form_label(form.value, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
Upvotes: 1