zostera / django-bootstrap4

Bootstrap 4 integration with Django.
https://django-bootstrap4.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.03k stars 262 forks source link

[Question] Adding CSS classes to widgets #81

Open nategro opened 6 years ago

nategro commented 6 years ago

I am looking for an opportunity to add custom css classes to a form widget and extend its 'form-control' class by using the template tag. Unfortunately the parameter 'field_class' modifies a higher-level DIV.

dyve commented 5 years ago

If there is no interest in discussing this any further, I think we should close this issue.

1358 commented 3 years ago

Just stumbleded around this issue trying to find an "easy" way to add custom css (and data-attributes) to a widget (in order to use bootstrap-select). Kinda surprised that this is not supported.

1358 commented 3 years ago

However you can use django-widget-tweaks in order to customize the input widget before it is handled by django-bootsrap4. This might be a nice solution:

{% bootstrap_field form.field|add_class:"what_ever_class_you_like"|attr:"data-foo:bar" %}