Skip to content

Multiple fields support #799

@azmeuk

Description

@azmeuk

I could not find it clearly written on the specs, but HTML allows an input file to have several values. For instance this is valid HTML:

<input type="text" name="foo" value="bar">
<input type="text" name="foo" value="baz">

However, wtforms does not support this, and always consider the first item of the request for a given name (here bar).

if valuelist:
self.data = valuelist[0]

wtforms provides an alternative to manage several times the same input, with FieldList. However FieldList have some differences:

  • the input have an incremental suffix, so this makes JS reordering of the fields more complicated for instance
  • resizing of the data list must be done with append_entry and pop_entry, users cannot directly delete a field in the middle of the list
  • it allows to nest FormField and make complex forms.

I think wtforms could support multiple fields. For instance we could add a multiple field in Fields with a default value at False, matching the current behavior. If set to True field.data would return a list instead of a single value. Validators should validate each individual values.

This could help with the validators handle one single value part of #662

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature, or existing feature improvementquestionQuestion about WTForms behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions