1

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 !

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.