wtforms

Wtforms form field text enlargement

北战南征 提交于 2020-02-02 10:55:28
问题 I am new to using wtforms and flask and am trying to enlarge the physical field size and the font inside of it. Should I use a specific piece of code or change it with css. <div class="container"> <div class="col-md-12"> <form id="signinform" class="form form-horizontal" method="post" role="form" style="font-size:24px;"> {{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }} {{ wtf.form_field(form.first_name, autofocus=true) }} {{ wtf.form_field(form.last_name) }} {{ wtf.form

How to append a new wtforms FormField with initial data as default?

这一生的挚爱 提交于 2020-02-02 03:10:48
问题 I have a form with wtform , I want to add a new form JobItemForm to my form JobForm using append_entry . JobItemForm has selectField named company . I add choice field data via model like this form.jobs[0].company.choices = company_list now I use append_entry without any choices and I recieve an error. So how can I call append_entry with some initial data? class JobItemForm(Form): company = SelectField(_('company'), description=_('<a href="/education/institute/add/">new company"</a>')) title

WTForms date validation

时光毁灭记忆、已成空白 提交于 2020-01-30 03:32:11
问题 I am currently trying to build a simple web application using Flask. With this i am also using WTForms, however i am having problem with getting date information from the form and getting it validated. This is the form: from flask_wtf import FlaskForm from wtforms import SubmitField from wtforms.fields.html5 import DateField from wtforms.validators import DataRequired from datetime import date class LeasForm(FlaskForm): start_date = DateField("Start date", default=date.today(), format='%d/%m/

DateField is not rendered as type=“date”

人盡茶涼 提交于 2020-01-24 02:17:06
问题 class Form(Form): plan_start = DateField('Plan Start', validators=[Required()]) this code will render this html. <input id="plan_start" name="plan_start" type="text" value=""> My question is: why the type is text and not date ? I only can get this resolved by passing explicitly the type='date' in template. {% raw form.plan_start.label %}{% raw form.plan_start(type='date') %} 回答1: You can use the DateField from html5. from wtforms.fields.html5 import DateField class Form(Form): plan_start =

Dynamically adjusted forms inside FieldList

人走茶凉 提交于 2020-01-23 10:58:50
问题 I'm using Flask and Flask-WTF and I need to create a form that contains several blocks (subforms) of a similar structure (like a subform with one SelectField and one TextAreaField ). As the docs suggest, I can use FormField together with FieldList to achieve this goal. However, I need to tweak my SelectField 's dynamically (changing their choice s at runtime according to values in the database). The docs now suggest Note that the choices keyword is only evaluated once, so if you want to make

Setting default value after initialization in SelectField flask-WTForms

蹲街弑〆低调 提交于 2020-01-23 07:50:55
问题 I would like to pre-select the value for SelectField when displaying it to user. default argument works when it is passed at the time of instantiation but does not work once the field is initialized. class AddressForm(Form): country = SelectField('Country',choices=[('GB', 'Great Britan'), ('US', 'United States')], default='GB') # works When I try to use default value to preselect option before presenting the form to user for editing, it doesn't work. address_form = AddressForm() address_form

Wtforms: adding dynamic fields with multiple inheritance

寵の児 提交于 2020-01-23 07:07:47
问题 I know I can create dynamic fields like this: http://wtforms.simplecodes.com/docs/1.0.1/specific_problems.html#dynamic-form-composition But the above solution is unwieldy in my case, and requires a special API which I would like to avoid. I am wondering if there is a way to get this working with multiple inheritance? I tried the following and it won't work and I don't know why, I figured that WTForms should bind the forms properly given how the class structure is working: >>> class Base(Form)

WTForms QuerySelectMultipleField Not sending List

情到浓时终转凉″ 提交于 2020-01-17 03:57:12
问题 I am working on a Flask Application to do some event scheduling. I am having problems with WTForms QuerySelectMultipleField in my form. forms.py class EnterEvent(Form): ... invitees = QuerySelectMultipleField('Invitees', query_factory=lambda: models.User.query.order_by(models.User.name).all()) and in my init .py file where I parse the Form POST data. Just to test I tried to return request.form['invitees'] just to see what is passed. Eventually I want to validate the data and add it to my

How to get SelectField current value with Flask WTF

柔情痞子 提交于 2020-01-16 09:02:13
问题 I making a gender form using Flask-WTF , here is the snippet of my code: class Gender(enum.Enum): Male = 'Male' Female = 'Female' def __str__(self): return self.value gender = [(str(y), y) for y in (Gender)] class EditStudentForm(Form): gender = SelectField('Gender', choices=gender) @app.route('/edit_student') def edit_student(): student = Student.query.filter_by(id=student_id).first() student_form = EditStudentForm() # ... validate on submit # .... # .... return render_template(student

Jinja, Flask and WTForms: how to pass parameters in field? [duplicate]

走远了吗. 提交于 2020-01-13 11:28:09
问题 This question already has answers here : Using Flask-WTForms, how do I style my form section of the html? (2 answers) Closed 3 years ago . I am following this tutorial http://flask.pocoo.org/docs/0.10/patterns/wtforms/ Here’s an example _formhelpers.html template with a macro: {% macro render_field(field) %} <dt>{{ field.label }} <dd>{{ field(**kwargs)|safe }} {% if field.errors %} <ul class=errors> {% for error in field.errors %} <li>{{ error }}</li> {% endfor %} </ul> {% endif %} </dd> {%