How to set class of select2 form
See original GitHub issueDAL is working great in my project, thanks for making such an amazing app. Problem is it’s not looking great and I can’t figure out how to set the form class properly.
I would like to set the form class to bootstrap ‘form-control input-lg’
Changing the class in the template just renders a the DAL form within the bootstrap form, even if I drop the form group and just use a single form tag.
Cannot figure out how to set in the forms.py with the data attributes, setting class = ‘class name’ here has not effect.
Forms.py
class CreatePartForm(forms.ModelForm):
part = forms.ModelChoiceField(
queryset=Design.objects.all(),
widget=autocomplete.ModelSelect2(url='PartsAutocomplete',attrs={
'data-placeholder': 'Add a part to your BOM',
})
)
class Meta:
model = Design
fields = ('part',)
def __init__(self, *args, **kwargs):
super(CreatePartForm, self).__init__(*args, **kwargs)
self.fields['part'].label = ''
Template.html
<form class='form' method='POST' action='#'>
<div class='form-group'>
{% csrf_token %}
{{ PartForm|crispy }}
</div>
<button type='submit' class='btn btn-success btn-lg' value='part'>
Add Part
</button>
</form>
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Add class to select2 element - jquery - Stack Overflow
I'm trying to add an error class to a select2 box for form validation. It's just a 1px red border. I found the...
Read more >Appearance | Select2 - The jQuery replacement for select boxes
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.
Read more >Need an additional custom class to select2-container #285
I am using version 4.0.2 . And on using containerCssClass it adds class to select2-selection . I guess the class is supposed to...
Read more >select2-bootstrap-theme
Those of you familiar with Select2 v3 remember that the default behavior was to copy the original elements CSS-classes to the container of...
Read more >Select2 and Bootstrap Integration by Keenthemes
Select2's CSS is highly customized in sass/vendors/plugins/_select2. · Select2's Javascript is globally initialized with some predefined settings in src/js/ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I don’t know if this could help you but I overwrite some of the CSS classes to make it look better with bootstrap.
This helped, but I also added some custom Styling to make the fields look good and responsive.