class FruitForm(forms.Form): autocomplete = forms.CharField( label='Type the name of a fruit (AutoCompleteWidget)', widget=selectable.AutoCompleteWidget(FruitLookup), required=False, ) newautocomplete = forms.CharField( label='Type the name of a fruit (AutoCompleteWidget which allows new items)', widget=selectable.AutoCompleteWidget(FruitLookup, allow_new=True), required=False, ) combobox = forms.CharField( label='Type/select the name of a fruit (AutoComboboxWidget)', widget=selectable.AutoComboboxWidget(FruitLookup), required=False, ) newcombobox = forms.CharField( label='Type/select the name of a fruit (AutoComboboxWidget which allows new items)', widget=selectable.AutoComboboxWidget(FruitLookup, allow_new=True), required=False, ) # AutoCompleteSelectField (no new items) autocompleteselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteField)', required=False, ) # AutoCompleteSelectField (allows new items) newautocompleteselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, allow_new=True, label='Select a fruit (AutoCompleteField which allows new items)', required=False, ) # AutoComboboxSelectField (no new items) comboboxselect = selectable.AutoComboboxSelectField( lookup_class=FruitLookup, label='Select a fruit (AutoComboboxSelectField)', required=False, ) # AutoComboboxSelectField (allows new items) newcomboboxselect = selectable.AutoComboboxSelectField( lookup_class=FruitLookup, allow_new=True, label='Select a fruit (AutoComboboxSelectField which allows new items)', required=False, ) # AutoCompleteSelectMultipleField multiautocompleteselect = selectable.AutoCompleteSelectMultipleField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteSelectMultipleField)', required=False, ) # AutoComboboxSelectMultipleField multicomboboxselect = selectable.AutoComboboxSelectMultipleField( lookup_class=FruitLookup, label='Select a fruit (AutoComboboxSelectMultipleField)', required=False, )
class CatalogItemEditForm(forms.ModelForm): item_category = forms.CharField( label='Begin typing to select an existing or add a new category.', widget=selectable.AutoComboboxWidget(ItemCategoryLookup, allow_new=True), required=True, ) class Meta: model = CatalogItem fields = CATALOG_ITEM_FIELDS def __init__(self, *args, **kwargs): kwargs.setdefault('initial', {}) if 'weight' not in kwargs['initial']: kwargs['initial']['weight'] = '' super(CatalogItemEditForm, self).__init__(*args, **kwargs) def clean_weight(self): weight = self.cleaned_data.get('weight') if weight == '': weight = None return weight def clean_item_category(self): name = self.cleaned_data.get('item_category') if name: category = ItemCategory.objects.filter(name__iexact=name).first() if not category: category = ItemCategory.objects.create(name=name) return category
class UniversityForm(forms.Form): university = forms.CharField( label='Universitet', widget=selectable.AutoComboboxWidget(UniversityLookup), required=False, ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
class ChainedForm(forms.Form): university = forms.CharField( label='Universitet', widget=selectable.AutoComboboxWidget(UniversityLookup), required=False, ) programme = forms.CharField( label='Program', widget=selectable.AutoComboboxWidget(ProgrammeLookup), required=False, ) semester = forms.CharField( label='Termin', widget=selectable.AutoComboboxWidget(SemesterLookup), required=False, ) course = forms.CharField( label='Kurs', widget=selectable.AutoComboboxWidget(CourseLookup), required=False, )
class FruitForm(forms.Form): autocomplete = forms.CharField( label='Type the name of a fruit (AutoCompleteWidget)', widget=selectable.AutoCompleteWidget(FruitLookup), required=False, ) newautocomplete = forms.CharField( label='Type the name of a fruit (AutoCompleteWidget which allows new items)', widget=selectable.AutoCompleteWidget(FruitLookup, allow_new=True), required=False, ) combobox = forms.CharField( label='Type/select the name of a fruit (AutoComboboxWidget)', widget=selectable.AutoComboboxWidget(FruitLookup), required=False, ) newcombobox = forms.CharField( label='Type/select the name of a fruit (AutoComboboxWidget which allows new items)', widget=selectable.AutoComboboxWidget(FruitLookup, allow_new=True), required=False, ) # AutoCompleteSelectField (no new items) autocompleteselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteField)', required=False, ) # AutoCompleteSelectField (allows new items) newautocompleteselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, allow_new=True, label='Select a fruit (AutoCompleteField which allows new items)', required=False, ) # AutoCompleteSelectField (no new items) comboboxselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteSelectField with combobox)', required=False, widget=selectable.AutoComboboxSelectWidget ) # AutoComboboxSelect (allows new items) newcomboboxselect = selectable.AutoCompleteSelectField( lookup_class=FruitLookup, allow_new=True, label='Select a fruit (AutoCompleteSelectField with combobox which allows new items)', required=False, widget=selectable.AutoComboboxSelectWidget ) # AutoCompleteSelectMultipleField multiautocompleteselect = selectable.AutoCompleteSelectMultipleField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteSelectMultipleField)', required=False, ) # AutoComboboxSelectMultipleField multicomboboxselect = selectable.AutoCompleteSelectMultipleField( lookup_class=FruitLookup, label='Select a fruit (AutoCompleteSelectMultipleField with combobox)', required=False, widget=selectable.AutoComboboxSelectMultipleWidget ) # AutoComboboxSelectMultipleField with disabled attribute disabledmulticomboboxselect = selectable.AutoCompleteSelectMultipleField( lookup_class=FruitLookup, label='Disabled Selectable field', required=False, widget=selectable.AutoComboboxSelectMultipleWidget, initial={'1', '2'}, ) def __init__(self, *args, **kwargs): super(FruitForm, self).__init__(*args, **kwargs) self.fields['disabledmulticomboboxselect'].widget.attrs['disabled'] = 'disabled'