In my form I am trying to create a custom array field with choices.
The custom form field:
class CustomField(Field):
widget = TextInput()
def _value(self):
if self.data:
return u', '.join(self.data)
else:
return u''
def process_formdata(self, valuelist):
if valuelist:
self.data = [x.strip() for x in valuelist[0].split(',')]
else:
self.data = []
The actual form calls the custom form field
class PostForm(Form):
status = CustomField()
Whenever, I post data to PostForm
it calls the custom field but does not pass in an any valuelist
to process_formatdata
. The custom field always returns a empty list.
Am I missing any thing here.
Your code works for me, here's a working example--
example.py
templates/test.html