I have a simple model forms, that is being rendered through the following jinja2 template:
<form method="POST" action="">
<table>
{% for field in form %}
<tr>{{ field.label }}</tr>
<tr>{{ field()|safe }}</tr>
<tr>
{% if field.errors %}
<td>
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</td>
{% endif %}
{% endfor %}
</table>
<input type="submit" class="btn" value="Submit Form"/>
</form>
I wanted to customize the output of the wtforms and to each of the form fields being rendered, i wanted to add a class "required" to use a jquery client side validation plugin.
Following is my appengine db model:
class Song(db.Model):
title = db.StringProperty()
lyrics = db.TextProperty()
duration = db.IntegerProperty()
movie = db.ReferenceProperty(Movie)
singer = db.ReferenceProperty(Singer)
and following is my form, rendering script:
SubTaskForm = model_form(Song,
exclude=('movie', 'singer'),
)
What would be a good way to attach validators using wtfroms validators, also how can i attach a class=required to the form fields?
Let me know how to do it.
One way would be to override the stuff in python, where you define them, another thing that can be done is, you might try in the templates itself,
<tr class="required">Give it a try, should work.