flask-wtf icon indicating copy to clipboard operation
flask-wtf copied to clipboard

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

Open feiticeir0 opened this issue 1 year ago • 0 comments

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)```

feiticeir0 avatar Nov 04 '24 11:11 feiticeir0