Delete or customize the inline form label

When I installed my form file, for example:

$builder->add( 'producer', new ProducerType() ); 

it always returns me a common title (label) for the nested form, for example, β€œproducer”, how can I remove or customize this label?

UPDATE: last Fosuserbundle has been removed from this annoying lable

+4
source share
4 answers

The correct (?) Way to remove a shortcut is to set it to false .

 $builder->add( 'producer', new ProducerType(), array( 'label' => false )); 

Then the tag will not be displayed at all. Although this is somehow missing from the documentation at the moment, you can reorganize this behavior by looking at the default twig form styles (3rd line):

 {% block form_label %} {% spaceless %} {% if label is not sameas(false) %} {% if not compound %} {% set label_attr = label_attr|merge({'for': id}) %} {% endif %} {% if required %} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} {% endif %} {% if label is empty %} {% set label = name|humanize %} {% endif %} <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label> {% endif %} {% endspaceless %} {% endblock form_label %} 

These branch styles are also a great start to customize your form. More information on this topic can be found in this cookbook entry .

+9
source

you can try adding a label as an option, depending on which ProductType options inherit, that might be enough.

 $builder->add('producer', new ProducerType(), array('label' => 'Some Label')); 
+3
source

To get an empty embedded form label, add an empty (single space char) label attribute

 $builder->add( 'producer', new ProducerType(), array('label' => ' ')) 

which leads to the following:

 <div id="producer"> <div> <label class=" required"></label> <div id="mainEntityName_producer"> <div> <label.../> <input.../> </div> </div> </div> </div> 
0
source

To avoid conflicts with formbuilder, you can disable shortcuts with css.

 <style> table.record_properties td label { display: none; } </style> <form action="{{ path('equipment_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}> <table class="record_properties" style="text-align: left;width: 500px;"> <tbody> <tr> <th>{% trans %}title{% endtrans %}</th> <td>&nbsp;</td> <td>{{ form_row(edit_form.title) }}</td> </tr> ... 
0
source

All Articles