所以我正在使用Symfony 2.7,并且在我的收藏表格上遇到了问题。
关于表单的重要一点是,一个活动可能具有多个“通勤”,因此就是收集表单。
我有一个主要形式,即活动形式,并有一种或几种“通勤”形式。
现在,我已经将我的主表单显示为普通表单,并通过另一个模板显示了“通勤”(因此是一个集合),如下所示:https://stackoverflow.com/a/54513245/9662283
仍然有一个问题,我的数据原型balise似乎在屏幕上出现了两次,这弄乱了数据库中的插入。
默认情况下,无论是否尝试覆盖它,它都会出现在我的主窗体下方,然后在覆盖它时出现。
是否有通过覆盖使其默认消失的方法?
The collection part of my main form :
<div id="activite_deplacement" data-prototype="
{% filter escape %}
{{ include('bundleName:Forms:prototype.html.twig', { 'forma': form.deplacement.vars.prototype }) }}
{% endfilter %}">
</div>
和
The prototype.html.twig part
<div class="card panel-info p-5 mt-3">
<div class="card-heading">
<h4 class="card-title">Déplacement</h4>
</div>
<div class="row" style="margin-top:20px;">
<div class="col-md-4">
{{ form_label(forma.children.siteDepart) }}
{{ form_widget(forma.children.siteDepart) }}
</div>
<div class="col-md-4">
{{ form_label(forma.children.transport) }}
{{ form_widget(forma.children.transport) }}
</div>
<div class="col-md-4">
{{ form_label(forma.children.dateDebutDep) }}
{{ form_widget(forma.children.dateDebutDep) }}
</div>
</div>
<div class="row" style="margin-top:20px;">
<div class="col-md-4">
{{ form_label(forma.children.siteDestination) }}
{{ form_widget(forma.children.siteDestination) }}
</div>
<div class="col-md-4">
{{ form_label(forma.children.km) }}
{{ form_widget(forma.children.km) }}
</div>
<div class="col-md-4">
{{ form_label(forma.children.dateFinDep) }}
{{ form_widget(forma.children.dateFinDep) }}
</div>
</div>
<div class="row" style="margin-top:20px;">
<div class="col-md-4">
{{ form_label(forma.children.tempsSurSite) }}
{{ form_widget(forma.children.tempsSurSite) }}
</div>
</div>
activiteType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nomActivite', 'text', array(
'label' => 'Activité',
'attr' => array(
'class' => 'form-control'
)
))
->add('descriptionActivite', 'textarea', array(
'label' => 'Description',
'attr' => array(
'class' => 'form-control'
)
))
->add('dateDebut', 'datetime', array(
'placeholder' => 'Select value',
'label' => 'Debut',
'data' => new \DateTime(),
'attr' => array(
'class' => 'form-control',
'style' => 'font-size: 18px',
'class' => 'bundleName:activite'
)
))
->add('dateFin', 'datetime', array(
'label' => 'Fin',
'data' => new \DateTime(),
'attr' => array(
'class' => 'form-control',
'style' => 'font-size: 18px',
'class' => 'bundleName:activite'
)
))
->add('categorie', 'entity', array(
'label' => 'Catégorie',
'class' => 'bundleName:Categorie',
'choice_label' => 'nomCategorie',
'required' => true,
'placeholder' => '-- Catégorie... --',
'attr' => array(
'class' => 'form-control'
)
))
->add('projet', 'entity', array(
'label' => 'Projet',
'class' => 'bundleName:Projet',
'choice_label' => 'nomProjet',
'empty_value' => '-- Projet ... -- ',
'attr' => array(
'class' => 'form-control'
)
))
->add('tache', 'entity', array(
'label' => 'Tâche',
'class' => 'bundleName:Tache',
'choice_label' => 'nomTache',
'empty_value' => '-- choisir --',
'required' => true,
'attr' => array(
'class' => 'form-control'
),
->add('deplacement', 'collection', array(
'type' => new DeplacementType(),
'options' => array('label' => false),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => true
))
->add('reset', 'reset', array(
'label' => 'Réinitialiser',
'attr' => array(
'class' => 'btn btn-warning btn-block'
)
))
->add('valider', 'submit', array(
'label' => 'Valider',
'attr' => array(
'class' => 'btn btn-primary btn-block'
)
));
}