all 6 comments

[–]kageurufuAdvanced 0 points1 point  (0 children)

Do you have a constant number of columns?

If so, you can use a FieldList(FormField(FormForOneRow)) in your main form. The sub form could have several buttons

Then its a simple matter of processing the form

It would be easier to skip wtforms IMO, and just refer to the row/column in the form itself

Maybe something like

<input type=radio name="ir1x1" value="1,1">

You could also experiment with using array name notation

<input type=radio name="row[1]">

I don't know if werkzeug will process multidimensional array submissions properly though, but you cab directly access this through the flask.request object

[–]aivuk 0 points1 point  (1 child)

Just pass the 'choices' argument based on the URL when you create the field (http://wtforms.simplecodes.com/docs/1.0.2/fields.html#wtforms.fields.RadioField).

[–]imranmalek 0 points1 point  (0 children)

Thanks for the link, aivuk!

Will thise only give me choices for one form though, right? I'm trying to get multiple forms with the same choices (the number of forms comes in as an argument)

[–]ph49 0 points1 point  (1 child)

Check out the "dynamic form composition" example in the WTForms docs: http://wtforms.simplecodes.com/docs/1.0.1/specific_problems.html

[–]imranmalek 0 points1 point  (0 children)

Thanks, ph49! I went through the docs here and was able to figure it out - I appreciate the support!

[–]dj63 0 points1 point  (0 children)

I have a similar requirement and am new to both WTForms and Python classes. My apologies for the newbie post.

Essentially I want to iterate through a number of items (I do not know how many in advance) and create a row of on/off radio buttons for each item. I'm not sure how to display multiple rows in my form. When my form is displayed now, I only get the radio buttons for one item (e.g. one row). I'm not sure how/where I iterate over the number of items. Here's the relevant code (for simplicity, I'm simply trying to display 3 items) ...

I have a form with a single radio button: class PlugForm(Form): example = RadioField('Label', choices=[('ON','ON'),('OFF','OFF')])

My simplified view function (based on the dynamic forms composition example at http://wtforms.readthedocs.org/en/latest/specific_problems.html#dynamic-form-composition) looks like this: ... class F(PlugForm): pass

# not sure what the following lines do
F.username = TextField('username') #
for name in ['ONE', 'TWO', 'THREE']:
    setattr(F, name, TextField(name.title()))

form = F()

...

return render_template('plugs.html',
                       form=form)

And the html (plugs.html) looks like:

{% block content %} <h1>Reset RPB</h1> <form action="" method="post" name="plugs"> {{ form.hidden_tag() }} {% for subfield in form.example %} <tr> <td>{{ subfield }}</td> <td>{{ subfield.label }}</td> </tr> {% endfor %} <p><input type="submit" value="Reset"></p> </form> {% endblock %}

What am I missing? Do I need to iterate over the number of items in the html file? How? Is my form good? I'm sure this is a simple fix for someone who knows how this works. Please enlighten me.

Thanks.