3

如果我在表单中嵌入表单类型集合。我已将 allow_add 设置为 true。如何覆盖原型输出。假设我想在每次添加时将表单类型的集合包装在一个表中。认为我可以在 jquery 中使用原型输出,但更愿意从一开始就做到这一点。例如,我的收藏是以下类型:

class EmailShareType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
       $builder->add("shareName","text",array("label"=>"Recipient Name:"));
       $builder->add("emailName", "email", array("label"=>"Recipient Email:","required" => true));
       $builder->add("emailMessage", "textarea",array("label"=>"Enter email message", "max_length" => "4000"));
    }

    public function getName() 
    {
        return 'emailShare';
    }    
} 

并且生成的原型呈现为:

data-prototype="
<div>
<label class="required">__name__label__</label>
<div id="emailShareCollection_emailShares___name__">
<div>
<label for="emailShareCollection_emailShares___name___shareName" class="required">Recipient Name:</label>
<input type="text" id="emailShareCollection_emailShares___name___shareName" name="emailShareCollection[emailShares][__name__][shareName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailName" class="required">Recipient Email:</label>
<input type="email" id="emailShareCollection_emailShares___name___emailName" name="emailShareCollection[emailShares][__name__][emailName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailMessage" class="required">Enter email message</label>
<textarea id="emailShareCollection_emailShares___name___emailMessage" name="emailShareCollection[emailShares][__name__][emailMessage]" required="required" maxlength="4000"></textarea>
</div>
</div>
</div>"

如何控制此输出?

4

1 回答 1

5

你可以通过传递一个custom template

data-prototype="{% filter escape %}{% include 'YourBundle:YourController:yourTemplate.html.twig' with {'form': form.collectonField.get('prototype')} %}{% endfilter %}"
于 2013-09-22T21:58:22.617 回答