547n00n
547n00n

Reputation: 1536

add bootstrap class to dateTime attribute Symfony

I have a symfony crud actions , in the new and edit form I want to add bootstrap class to the datetime attribute.

here is the formType :

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', Field\TextType::class, array(
                        'label'     => 'w2d.product.backend.event.entityFields.name',
                        'required'  => true
                 ))
                 ->add('description', Field\TextareaType::class, array(
                        'label'     => 'w2d.product.backend.event.entityFields.description',
                        'required'  => true
                 ))
                 ->add('startDate', Field\DateTimeType::class, array(
                        'label'     => 'w2d.product.backend.event.entityFields.startDate',
                        'required'  => true
                 ))
                 ->add('endDate', Field\DateTimeType::class, array(
                        'label'     => 'w2d.product.backend.event.entityFields.endDate',
                        'required'  => true
                 ));



    }

and here is the twig form call :

    {{ form_start(form) }}
    {{ form_errors(form) }}
<fieldset>
    {{ form_row(form.name) }}
</fieldset>
<fieldset>
    {{ form_row(form.description) }}
</fieldset>
<fieldset>
    {{ form_row(form.startDate) }}
</fieldset>
<fieldset>
    {{ form_row(form.endDate) }}
</fieldset>
<fieldset class="txtRight">
    <hr />
    {% if event.id %}
        <input type="submit" value="{{ 'w2d.core.global.update'|trans }}" />
    {% else %}
        <input type="submit" value="{{ 'w2d.core.global.add'|trans }}" />
    {% endif %}
</fieldset>
{{ form_end(form) }}

Can some one help please , just I want the bootstrap class in the datetime field. Thanks !

Upvotes: 1

Views: 191

Answers (1)

Nicolai Fr&#246;hlich
Nicolai Fr&#246;hlich

Reputation: 52493

You can add the class (by adding form-options during rendering of the sub-field) in your twig template like this:

<fieldset>
    {{ form_row(form.startDate, {'attr': {'class': 'bootstrap-class'}}) }}
</fieldset>

Upvotes: 2

Related Questions