形式主题和Symfony收藏
我想添加特殊的样式到我的CollectionType
中,我在这里得到了一个解决方案:Symfony / Jquery对象集合。 现在我有一个我无法解决的问题:
我有这个自定义form_row:
// src/MyBundle/Ressources/views/CustomForms
{% block form_row %}
<div class="row">
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form) -}}
</div>
</div>
</div>
<br/>
{% endblock %}
这在一种情况下完美的工作,但现在我有一个FormFlow(CraueFormFlow),我的多步骤形式之一是:
class AddChildStep3 extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('childsFamily', CollectionType::class, array(
'entry_type' => RelationshipType::class,
'allow_add' => true
));
}
public function getBlockPrefix()
{
return 'AddChildStep3';
}
这呈现了这种形式的集合:
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('relRole', EntityType::class, array(
'class' => 'VSCrmBundle:RelRole'
))
//->add('sourceId', PersonChildType::class)
->add('destinationId', PersonRelationshipType::class);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'VSCrmBundleEntityRelationship'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'vs_crmbundle_relationship';
}
问题是我之前定义的form_row非常适合relRole
的最后一个窗体,但destinationId
属性显示了这一点:
因此, DestinationId
标签位于<div class="col-lg-4...
并且该小部件也在<div class=col-lg-4...
内部<div class=col-lg-4...
然后在小部件内部,我还有一个时间标签在<div class="col-lg-4 ...
我想通过为这部分特别添加一个新的自定义form_rom来解决这个问题,所以我在profiler->forms->my form->vars->unique_block_prefix = _AddChildStep3_childsFamily
找到了该块的名称,并尝试这样做:
{% block _AddChildStep3_childsFamily_entry_row %}
<div class="row">
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.relRole, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.relRole) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.relRole) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.firstName, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.firstName) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.firstName) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.lastName, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.lastName) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.lastName) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.bornOn, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.bornOn) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.bornOn) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.profession, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.profession) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.profession) -}}
</div>
</div>
<br/>
</div>
{% endblock %}
由于它是在文档中编写的(http://symfony.com/doc/current/form/form_customization.html#how-to-customize-a-collection-prototype),但这不起作用...
PS:对于我的HTML在这种情况下是
<div class="row">
<div id="familyMembersList" data-prototype="{{ form_widget(form.childsFamily.vars.prototype)|e('html_attr') }}">
</div>
</div>
编辑:当我去探查器/小枝我没有看到那个小枝使用我的自定义输入行...也许自定义块的名称是错误的? 我找到了我必须在stackoverflow上自定义的块的名称。
好吧,经过一些头痛和几次尝试后,我发现Symfony / Form / twig不想自定义输入行。 我试过这个:
{% block _AddChildStep3_childsFamily_entry_widget %}
<div class="row">
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.relRole, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.relRole) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.relRole) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.firstName, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.firstName) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.firstName) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.lastName, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.lastName) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.lastName) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.bornOn, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.bornOn) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.bornOn) -}}
</div>
</div>
<br/>
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_label(form.destinationId.profession, "", {'label_attr': {'class': 'pull-right'}}) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_widget(form.destinationId.profession) -}}
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
{{- form_errors(form.destinationId.profession) -}}
</div>
</div>
<br/>
</div>
<br/>
{% endblock %}
即使这样也不完美。 希望它可以帮助:)
链接地址: http://www.djcxy.com/p/81403.html