0

I have a FormType that have this datetime input:

    $builder->add('data_inicio', 'datetime', array(
        'input' => 'datetime',
        'date_widget' => 'single_text',
        'time_widget' => 'choice',
        'attr' => array(
            'class' => 'datetime rangeDataInicio',
            'maxlength' => '10',
            'placeholder' => 'dd/mm/aaaa',
        ),
        'date_format' => 'dd/MM/yyyy',
        'required' => true,
        'disabled' => $isDisabled,
    ));

Form some reasons, I have to insert the placeholder and the class direct at the single_text date input, but both of them stays at the container and don't go to the input.

I tried a several ways to do this and all of them failed and searched the web for a couple of weeks and found nothing that could sove my problem. How can I put these two attrs at the input?

1
  • Why not use jquery datetime picker instead? Feb 7, 2013 at 12:24

1 Answer 1

1

You can use form theme for this.

{% form_theme form _self %}

{% block datetime_widget %}
{% spaceless %}
    {% if widget == 'single_text' %}
        {{ block('field_widget') }}
    {% else %}
        <div {{ block('widget_container_attributes') }}>
            {{ form_errors(form.date) }}
            {{ form_errors(form.time) }}
            {{ form_widget(form.date) }}
            {{ form_widget(form.time, { 'attr': {'class': 'datetime rangeDataInicio', 'placeholder': 'dd/mm/aaaa'} })) }}
        </div>
    {% endif %}
{% endspaceless %}
{% endblock datetime_widget %}
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.