Hi!
I am struggling to get MultiValueField and MultiWidget to work.
I have a CharField and ChoiceField in the MultiValueField class,
but I can't get the choices to show in the select tag.
Am I doing something wrong?
This is what I have so far:
class AutocompleteWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.Select(), forms.TextInput())
super(AutocompleteWidget, self).__init__(widgets, attrs=attrs)
def decompress(self, value):
if value:
return [value[0], value[1]]
return [None, None]
class AutocompleteField(forms.MultiValueField):
default_error_messages = {
'invalid': _(u'Enter a list of values.'),
'required': _(u'Please select or enter an value.'),
}
def __init__(self, *args, **kwargs):
choices = kwargs.pop('choices')
fields = (forms.ChoiceField(choices=choices), forms.CharField
())
widget=AutocompleteWidget
super(AutocompleteField, self).__init__(fields=fields,
widget=widget, *args, **kwargs)
def compress(self, data_list):
if data_list not in settings.EMPTY_VALUES:
return data_list
return None
class TestForm(forms.Form):
name = forms.CharField(required=True)
description = forms.CharField(required=True, widget=forms.Textarea
())
selection = AutocompleteField(choices=(('1', '1'), ('2', '2')),
required=True)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---