FilteredSelect

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class FilteredSelect(forms.widgets.Select):
    """
        Displays as an ordinary selectbox with an additional text-input for filtering the options.
        Requires: http://www.barelyfitz.com/projects/filterlist/filterlist.js

        Author: Konrad GiƦver Beiske
        Company: Linpro
    """
    class Media:
        js = ('filterlist.js', )

    pre_html = """
                   Filter: <INPUT NAME=regexp onKeyUp="%s_filter.set(this.value)"/> 
                   <INPUT TYPE=checkbox NAME="toLowerCase"
                          onClick="%s_filter.set_ignore_case(!this.checked)"
                   /> Case-sensitive <br>
               """
    post_html = """
                    <SCRIPT TYPE="text/javascript">
                    <!--
                    var %s_filter = new filterlist(document.getElementById("id_%s"));
                    //-->
                    </SCRIPT>
                """
    def render(self, name, value, attrs=None, choices=()):
        super_res = super(FilteredSelect, self).render(name, value, attrs=attrs, choices=choices)
        return (self.pre_html%(name, name)) + super_res + (self.post_html%(name, name))

More like this

  1. FilterManager by sergejdergatsjev 4 years, 5 months ago
  2. Google Closure support in django-compress by fabrice.bonny 3 years, 6 months ago
  3. Mod to allow simple_tag to access context by leaf 4 years, 7 months ago
  4. YUI Autocomplete by pigletto 5 years, 8 months ago
  5. create_object and update_object for newforms by danjak 6 years, 2 months ago

Comments

(Forgotten your password?)