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?
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 %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.