question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idea: Make Bootstrap Compatible

See original GitHub issue

There’s this theme https://github.com/select2/select2-bootstrap-theme

But currently not compatible with django-autocomplete-light even if I add the theme manually since I can’t apply it to the Widgets (constructor doestn’t recognize theme param) nor do I know how to apply it as the Select2 default theme after the Select2 script is added but before the select2() function is called.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Jan 14, 2019

@carlos22 thanks for this tip. finally got this working. Although slightly different implementation (see below). Also, for anyone else driven crazy by the height of the select box open your select2-bootstrap4.css file, and add min-height to class: .select2-container–bootstrap4 .select2-selection { min-height: 40px; }

class NewPostForm(forms.ModelForm): target = forms.ModelChoiceField( queryset=Celebrities.objects.all(), widget=autocomplete.ModelSelect2() )

class Meta:
    model = Post
    fields = ['target', 'content']

def __init__(self, *args, **kwargs):
    super(NewPostForm, self).__init__(*args, **kwargs)
    self.fields['target'].widget.attrs = {
        'data-theme': 'bootstrap4',
    }
2reactions
carlos22commented, Aug 3, 2018

This works for me (using bootstrap 4 theme from https://github.com/berkan52/select2-bootstrap4-theme)

$(document).one('autocompleteLightInitialize', '[data-autocomplete-light-function=select2]', function() {
    $.fn.select2.defaults.set( "theme", "bootstrap4" );
});

Just add anywhere in your js (after jquery is loaded).

Oh and make sure the css file is loaded AFTER the select2.css bundeled with this package. E.g.

<link rel="stylesheet" href="{% static "assets/select2-bootstrap4.css" %}" />
</body>
Read more comments on GitHub >

github_iconTop Results From Across the Web

New Project: Bootstrap | IntelliJ IDEA Documentation - JetBrains
The feature is supported only in the Ultimate edition when the HTML Tools plugin is installed and enabled. The HTML Tools plugin is...
Read more >
CSS · Bootstrap
Bootstrap makes use of certain HTML elements and CSS properties that require the use of the HTML5 doctype. Include it at the beginning...
Read more >
How to make Bootstrap responsive layout work on IE8
By suggestions, I tried adding <meta http-equiv="X-UA-Compatible" content="IE=edge" /> , respond.js or css3-mediaqueries-js , but none of them helped. Here's a ...
Read more >
The Ultimate Guide to Bootstrap CSS - HubSpot Blog
Junior developer using Bootstrap CSS to create responsive website ... It's also fully customizable, and compatible with all modern browsers.
Read more >
Bootstrap (front-end framework) - Wikipedia
Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It contains HTML, CSS and (optionally) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found