When I use the validator wtforms.IntegerFieldwith required, I only ever get the message "this field is required."
On the other hand, it seems that it IntegerFieldmay only be required and that I should not use the required validator.
What is the logic here? Doesn't it make sense that this field just adds an integer validator, and should it still be used as a required field (but should be int) or not necessarily a field?
Just try to find some patterns here.
Update:
- WTForms Version
__version__ = '1.0.5' - Flask_WTF Version
__version__ = '0.9.3'
The form
class OrderForm(Form):
order_number = wtforms.IntegerField('Order Number', validators=[validators.Required()])
View
def render_response(self):
ctx = {}
order_form = OrderForm()
ctx['order_form'] = order_form
if order_form.validate_on_submit(): pass
return render_template('support/warranty_form.html', **ctx)
Template
{% macro render_field(field) %}
<div class="form-field-wrapper">
<div class="form-field">
{{ field(**kwargs) }}
</div>
{{ render_field_errors(field) }}
</div>
{% endmacro %}
{{ render_field(order_form.order_number, placeholder="ORDER NUMBER") }}
If I remove the required validator, my form still requires a value.

Instead, I used a custom validator instead of a text field.