pallets-eco / pallets-eco/wtforms

Multiple fields support

Open
#799 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement question
Dominant language
Python
Stars
1.6k
Forks
409
PR merge metrics
No merged PRs in 30d

Description

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).
https://github.com/pallets-eco/wtforms/blob/9f9146c8ee2cb2b2e7b3d9bc09ac7e433fd55bb0/src/wtforms/fields/core.py#L362-L363

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/wtforms/fields/core.py at the request-value handling around lines 362-363, and compare the existing FieldList behavior and the concerns linked from issue #662. Determine the supported API for a multiple field, including how field.data and validators should behave, then add coverage showing repeated names are handled without changing the default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.