1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django import forms
5 from django.utils.translation import ugettext_lazy as _
7 from search.fields import JQueryAutoCompleteSearchField
10 class SearchForm(forms.Form):
11 q = JQueryAutoCompleteSearchField(label=_('Search'))
12 # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
14 def __init__(self, source, *args, **kwargs):
15 kwargs['auto_id'] = False
16 super(SearchForm, self).__init__(*args, **kwargs)
17 self.fields['q'].widget.attrs['id'] = 'search'
18 self.fields['q'].widget.attrs['autocomplete'] = 'off'
19 self.fields['q'].widget.attrs['data-source'] = source
20 if 'q' not in self.data:
21 self.fields['q'].widget.attrs['placeholder'] = _('title, author, epoch, kind, genre, phrase')