python 3.x - Wtforms.fields.html5 DateField not working as plain old DateField in Flask -
i have problem getting html5 datepicker provide value form in flask using wtf-forms. same form working expected if drop html5 datefield plain old vanilla wtf-forms datefield.
for curious: versions: python 3.5.2, flask: 0.11.1, flask-wtf: 0.12
the relevant code be:
model:
class order(db.model): __tablename__ = 'orders' paid_date = db.column(db.datetime, nullable=true)
form shouldn't make difference completeness here snippet order-update.html:
<div class="form-group"> {{ form.paid_date.label }} {% if form.paid_date.errors %} {% error in form.paid_date.errors %} <p class="error-message">{{ error }}</p> {% endfor %} {% endif %} {{ form.paid_date }} </div>
minimal controller:
@app.route('/orders/update/<int:order_number>', methods=['get', 'post']) def update_order(order_number): order = order.query.get(order_number) if request.method == 'post': if not form.validate(): return render_template('update-order.html', form=form, order=order) else: form.populate_obj(order) db.session.commit() return redirect(url_for('user') elif request.method == 'get': return render_template('update-order.html', form=form, order=order)
here works form declaration:
from flask_wtf import form wtforms import datefield class updateorderform(form): paid_date = datefield('date order paid', format='%m/%d/%y', render_kw={'placeholder': '6/20/15 june 20, 2015'}) submit = submitfield('update order')
while following break:
from flask_wtf import form wtforms.fields.html5 import datefield class updateorderform(form): paid_date = datefield('date order paid', format='%m/%d/%y', render_kw={'placeholder': '6/20/15 june 20, 2015'}) submit = submitfield('update order')
to describe behavior, plain datefield
, render form string input (which displaying present value should after form.populate_obj()
allows me stick in new date, e.g., 9/12/16
, , passes controller form.paid_date
datefield
, has value of 09/20/16
, , form.paid_date.data=2016-09-20
. passes validation , commits db.
when switch html5 date picker, nice have, render form datepicker (i set present date in object btw) has form.paid_date
above, i.e., datefield
, value
same. however, datepicker showing mm/dd/yyyy
. if enter 09/20/2016
either hand or picker , submit, form.paid_date.data
comes none
. furthermore, have
process_errors = <class 'list'>: ['not valid date value']
raw_data = <class 'list'>: ['2016-09-20']
.
so see data returned, doesn't pass form processing , placed data slot. can write code pull out raw_data
surely missing or bug!?
i found out in chrome browser raw_data
['2011-01-01']
doesn't match time format!
you should change this:
format='%y-%m-%d',
Comments
Post a Comment