Skip to content

"DateField in WTForms triggers 'Not a valid date value' error when left empty, even with no validators" #614

@feiticeir0

Description

@feiticeir0

Description of the Problem:
The DateField in WTForms triggers a 'Not a valid date value' validation error when left empty, even if no validators are specified. This behavior prevents the field from being optional and can result in unexpected validation failures.

Reproduction Steps:

  1. Create a FlaskForm with a DateField and no validators.
  2. Submit the form with the DateField left empty.
  3. Observe that the field triggers a validation error.

Expected Behavior:
The DateField should pass validation when empty, as no validators are present to enforce input.

Environment Details:

  • WTForms version: 3.2.1
  • Flask version: 3.0.3
  • Python version: 3.12.3

Code Example:

class ExampleForm(FlaskForm):
    date_field = DateField('Date', format='%Y-%m-%d', validators=[])

@app.route('/test', methods=['GET', 'POST'])
def test_view():
    form = ExampleForm()
    if form.validate_on_submit():
        return 'Form submitted successfully!'
    return render_template('test.html', form=form)```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions