For a template that includes a date field widget, non-date input fields will have their background colors changed per CSS. The same does not occur on the date widget. How should the background color of the date widget be effected? (Adding an attr array in the form class has no effect.)
A screenshot of the (small but real) difference:
Code samples: Template:
<td>{{ form_widget(form.fname, {'attr': {'class':'smallform'}}) }}
<td>{{ form_widget(form.sname, {'attr': {'class':'smallform'}}) }}
<td>{{ form_widget(form.dateAdded, {'attr': {'class':'smallform'} }) }}
Form class:
->add('fname', null, array('required' => false))
->add('sname', null, array('required' => false))
->add('dateAdded', 'date', array(
'widget' => 'choice',
'format' => 'MM/dd/yyyy',
'pattern' => '{{ year }}-{{ month }}-{{ day }}',
'years' => range(Date('Y'), Date('Y') - 5),
'required' => false,
'data' => date_create(),
))
CSS:
.smallform {
background-color: #f5f5f5;
font-size: 9pt;
color: #000066;
border: 1px solid #CCCC99;
}
Try:
also, view-source to make sure the classes are actually set in the html tags, it could be a problem with your CSS.
There is a problem with these lines:
<td>{{ form_widget(form.fname, {'attr': {'class':'smallform'}}) }}</td>
I dont think you can set a class on the entire widget, only for individual rows. you can try this if you need to set the class via twig.
A less-than-subtle solution: modify the date widget in my application's customized copy of fields.html.twig. The more precise solution would be to define a specific widget for this, or figure out how to retain the class attribute all the way into the date widget: