ARTICLE AD BOX
I have build a web page that dynamically creates a form of inputs that has always different names.
I achieved this by adapting the individual input field name attribute so I managed assosiate the value with the name. So when I send the form to python, I can splice the name and I associate the name and the value.
However I find it difficult to achieve with WTFs.
Below is generated by Javascript. The name consists of slots-(index) which is used by the 'FieldList' and the suffix unique_info_x .
<ul id="slots"> <li><input type="number" name="slots-0-unique_info_0"></li> <li><input type="number" name="slots-1-unique_info_1"></li> </ul>PYTHON:
from flask import Flask, render_template, request, session, url_for, redirect, flash from wtforms import FieldList, IntegerField from wtforms.validators import NumberRange from flask_wtf import FlaskForm class SlotInputForm(FlaskForm): slots = FieldList(IntegerField('slots', validators=[NumberRange(message='Insert numbers between 0 - 100 only.', min=0, max=100)] )) @app.route('/', methods=['GET', 'POST']) def mainpage(): form = SlotInputForm() if form.validate_on_submit(): # Here I should have access to the value of the input and the unique_info_x string which is part of the name return render_template('index.html', form=form) if __name__ == '__main__': app.run(debug=True)What I am looking is someway I am able to iterate form details in a way that I would have the validation done on the inputs and also unique_info_x suffix available as data together with the actual value.
I found some information over adapting more information on the name attribute as described. But I am having trouble understanding how to iterate it when it is sent to flask for validation.
Maybe there is someway I can hide the unique_info_X? Maybe using labels?
Can you help?
