wtforms icon indicating copy to clipboard operation
wtforms copied to clipboard

Amend `InputRequired` validator to support multi-input fields

Open dalepotter opened this issue 4 years ago • 1 comments

Small change to the InputRequired validator, so that it examines the entire contents of field.raw_data for validation logic (rather than just the first element). This is helpful when the HTML representation of a Field renders more than one <input>- e.g. using a widget.

For example, a WTForms implementation of the Gov.UK Design System Date Input component renders three HTML <input> elements. Prior to this fix, missing input in the first (i.e. Day, or raw_data[0]) input triggers a ValidationError, even if data was entered in the second (i.e. Month, or raw_data[1]) and/or third (i.e. Year, or raw_data[2]) inputs.

Commit checklist:

  • [x] add tests that fail without the patch - see 9797106d
  • [x] ensure all tests pass with pytest
  • N/A add documentation to the relevant docstrings or pages
  • [x] add versionadded or versionchanged directives to relevant docstrings - see 7a87422
  • [x] add a changelog entry if this patch changes code - see 7a87422

dalepotter avatar Dec 05 '21 22:12 dalepotter

Hi. Thank you for your patch. I am very interested in the subject of wtforms being able to manage several input. This may be related to #662. I think I have to take some time to think of all the implications, so that would be when I am a little less busy. But I do not forget.

azmeuk avatar Dec 23 '21 09:12 azmeuk