Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fields support #799

Open
azmeuk opened this issue Jul 27, 2023 · 1 comment
Open

Multiple fields support #799

azmeuk opened this issue Jul 27, 2023 · 1 comment
Labels
enhancement New feature, or existing feature improvement question Question about WTForms behavior

Comments

@azmeuk
Copy link
Member

azmeuk commented Jul 27, 2023

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/wtforms/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

@azmeuk azmeuk added the enhancement New feature, or existing feature improvement label Jul 27, 2023
@davidism
Copy link
Member

davidism commented Jul 27, 2023

I've thought about this before, but it feels like we're getting to the point of requiring a huge redesign of the entire library. There are nuances to accepting both single and list, validating each item or the whole list, handling a list of same-named fields where only some where filled out, applying required appropriately, etc. This is partially what I commented about in #662, because the current way we handle data is inconsistent and incomplete compared to what's possible in HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or existing feature improvement question Question about WTForms behavior
Development

No branches or pull requests

2 participants