PabloM
PabloM

Reputation: 29

error using DatePicker, I keep getting Not a valid date value even with the correct formatting. I need help, I can't figure out what is wrong

I am working on a project and one of the modules are related to an appointment site using wtfform+DataField+flask My form in appointment.html looks like this:

<form action="#" method="post" name="myform">
    {{ form.csrf_token }}
    {{ wtf.quick_form(form, novalidate=True, button_map={"submit": "primary"}) }}

my forms.py:

class DateForm(FlaskForm):
    date = DateField("Date", format="'%Y-%m-%d'", validators=[Optional()])
    hour = TimeField("Hour", format="'%H:%M'", validators=[Optional()])
    submit = SubmitField("Submit")

My main.py

@app.route("/appointment", methods=["GET", "POST"])
def appointment():
    form = DateForm()
    if form.validate_on_submit():
            session["date"] = form.date.data
            session["hour"] = form.hour.data
            return redirect(url_for('date'))
    return render_template("appointment.html", form=form, current_user=current_user)
@app.route('/date', methods=['GET', 'POST'])
def date():
date = session["date"]
        hour = session["hour"]
        return render_template('date.html')

I have tested other alternatives but with the same result. No matter what, I'm still seeing the "Not a valid date value" and "Not a valid time value" messages. I appreciate any help. Thanks!!!

appointment

Upvotes: 0

Views: 565

Answers (1)

PabloM
PabloM

Reputation: 29

I've already solved this problem by adding InputRequired() as validator y the form, just like this:

date = DateField("Fecha", validators=([InputRequired(), DataRequired()]))
hour = TimeField("Hora", validators=([InputRequired(), DataRequired()]))

Upvotes: 1

Related Questions