I'm building a flask app and I am taking an input from the user that has a number and a choice from a menu (daily, weekly, monthly, annually) ..
That's currently my code for the HTML page
{% for field in form %}
<div class="form-group">
<label for="">{{field.label}}</label>
{{field}} /
<select name="frequency" id="">
<option value="day">Day</option>
<option value="week" selected>Week</option>
<option value="month">Month</option>
<option value="year">Year</option>
</select>
</div>
{%endfor%}
python code where i need the value of select option menu:
if form.validate_on_submit():
for field in form:
weight=getItemTotalGrams(getItemWeight(field.name), field.data, request.form.get('frequency'))
where getItemTotalGrams takes 3 integers and getItemWeight takes name of item and returns its weight. Item is an object that has 2 attributes, name and weight.
so, I am able to get the value from the field to use it in python later but i don't know how to get the value from the select option menu, so i thought about including it in the field but couldn't find a way to do so.
So my question is either:
- is there a way where i can add a select field and integer field in WTF-Forms to connect the 2 input in one field?
- or how to get the value of the select option menu to use it in python?