I am trying to do validation of a FieldList which includes multiple RadioField I also tried the validation setup described here: https://github.com/wtforms/wtforms/issues/477 This is working and I have to select one of the radio buttons to submit. The form.validate_on_submit() condition is however never matched.
My forms:
class SelectRole(FieldsRequiredForm):
radio_group = RadioField(choices=[('one', 'Role_1'), ('two', 'Role_2'), ('three', 'Role_3'), ('four', 'Role_4')])
class RoleGroupMapping(FlaskForm):
role = FieldList(FormField(SelectRole), min_entries=1)
submit = SubmitField('Submit')
my view:
@app.route('/role_database', methods=['GET', 'POST'])
@login_required
def role_management_page():
form = RoleGroupMapping()
if form.validate():
print('FORM VALID')
else:
print('not validated')
return render_template('role_database.html', title='Role Database', form=form)
my html template:
{% extends "layout.html" %}
{% block content %}
<div class="row justify-content-center">
<div class="col-lg">
<div class="content-section">
<h3 class="mt-5">Group Mapping</h3>
<form action="" method="POST">
{{ form.hidden_tag() }}
{% for entry in form.role %}
<div class="row mt-2">
<div class="col">Role_XXX</div>
{% for radio_button in entry.radio_group %}
<div class="col">
{{ radio_button }}
{{ radio_button.label }}
</div>
{% endfor %}
</div>
{% endfor %}
<div class="form-group">
{{ form.submit(class="btn btn-outline-primary mt-3") }}
</div>
</form>
</div>
</div>
</div>
{% endblock content %}