Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For form fields using autocomplete, the form element class is set to 'form-text'. Bootstrap css uses 'form-control'. I've attached images showing how the form element is current rendered and how the form element is rendered if the class is 'form-control'.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2804221-7.patch | 2.58 KB | markhalliwell |
Comments
Comment #2
shelaneComment #3
markhalliwellThe only way this could be happening is if
bootstrap_textfield()
was being invoked directly rather than going through Drupal's normal theming system (e.g.drupal_render(array('#theme' => 'textfield', ...)
ortheme('textfield, $variables);
).The
form-control
class is automatically added in bootstrap_pre_render() for a multitude of element input types.Comment #4
shelaneWhere this issue comes up for me is in a custom module where I have a form. This is the element as defined:
$form['site_landingpage'] = array(
'#type' => 'entityreference',
'#title' => t('Default front page'),
'#era_entity_type' => 'node',
'#era_bundles' => array('landing_page','advanced_page'),
'#default_value' => get_entity_id(),
'#size' => 40,
'#description' => t('Select landing page to use as front page.'),
);
In order to use this entityreference type, I used the entityreference_autocomplete module. That module defines the type with these:
'#theme' => 'textfield',
'#theme_wrappers' => array('form_element'),
I just see that in this template file in the theme that it is setting the class to form-text. If I change it in the template file to form-control, then the form element displays with the correct class.
Comment #5
markhalliwellHm. Guess I'm just getting used to D8 where this class is added at a template level, regardless of what element info was defined.
Yes, they define
'#theme' => 'textfield"
for their element type:http://cgit.drupalcode.org/entityreference_autocomplete/tree/entityrefer...
I've taken a look at bootstrap_pre_render() and think it should probably be split up into theme hooks + element types.
I'll commit a fix shortly.
Comment #6
markhalliwellBetter title.
Comment #7
markhalliwellComment #9
m.stentaI updated to Bootstrap 7.x-3.18 and it seems that Date fields that use the Date Select widget (which shows each date component as a dropdown select list) are no longer receiving the "form-control" class, so they are being rendered as dropdown selects using the browser's default styling. I found this commit which changed the behavior of how that class is applied, so I assume this is what caused it. Does it make sense to start a new issue to fix that and link to this? Or reopen this one?
Comment #10
markhalliwellYes, also provide screenshots and markup examples of before/after please.
Comment #11
m.stentaCreated a new issue: #2939542: Date Select widget does not get .form-control class