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))
Comments