Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
StringField default value does not work #225
When setting a default value to a StringField it will not use this default value in case
class StringField(Field): """ This field is the base for most of the more complicated fields, and represents an ``<input type="text">``. """ widget = widgets.TextInput() def process_formdata(self, valuelist): if valuelist: self.data = valuelist else: self.data = '' # HERE THE DEFAULT VALUE IS OVERWRITTEN def _value(self): return text_type(self.data) if self.data is not None else ''
which overwrites the default value.
Probably this is enough to solve the problem:
def process_formdata(self, valuelist): if valuelist: self.data = valuelist elif self.data is None: self.data = ''
Anyway, why does the StringField set an empty string to data, couldn't it just use the parent's class Field.process_formdata method.
This is intentional behaviour for wtforms 2.x
It may work differently or be configurable in wtforms 3.x... but this option comes at the cost of security and it will be really clear to the user when they make that choice in wtforms 3