Select Dropdown Widget with jQueryUI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class SelectDropdownWidget(forms.Select):
    class Media:
        css = {
            'all': (
                iasettings.MEDIA_URL + 'js/selectmenu/ui.selectmenu.css',
            )
        }
        js = (
            iasettings.MEDIA_URL + 'js/selectmenu/ui.selectmenu.js',
        )

    def __init__(self, language=None, attrs=None):
        self.language = language or settings.LANGUAGE_CODE[:2]
        super(SelectDropdownWidget, self).__init__(attrs=attrs)

    def render(self, name, value, attrs=None):
        rendered = super(SelectDropdownWidget, self).render(name, value, attrs)
        return rendered + mark_safe(u'''<script type="text/javascript">
            $(document).ready(function afterReady() {
                var elem = $('#id_%(name)s');
                elem.selectmenu();
            });
            </script>''' % {'name':name})

More like this

  1. Multiple Select Widget with jQueryUI by maguspk 3 years, 10 months ago
  2. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 1 year ago
  3. jQuery Autocomplete by zeeg 6 years, 10 months ago
  4. Bootstrap button dropdown widget (replaces forms.Select) by benjaoming 1 year, 8 months ago
  5. Orderable inlines using drag and drop with jQuery UI by simon 5 years, 7 months ago

Comments

(Forgotten your password?)