Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help3403


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
 
Options:
RSS cloud
Jump to:

Dynamic WTForms and multiple button/submitfields

1 of 419 articles shown, currently no other people reading this forum.
photo
From: Nicholas T.
Date: Sat 16th May, 2:33pm
Actions: 
        Login-to-reply
Hi there,
Just having a lot of issues
As the quiz page has multiple questions only 1 question is served at a time (client-sided 
rendering). To do this in one implementation I used a dynamic form using RadioField:
def StyleOneForm(choices, *args, **kwargs):
	class StaticForm(FlaskForm):
		pass
	StaticForm.radioField = RadioField('radioField', coerce=int, choices=choices)
	StaticForm.submit = SubmitField('Submit')
	return StaticForm()
We want to have multiple implementation of quiz styles so we have complete data abstraction from 
display

Problem is the 2nd implementation uses a list of Button and WTForms doesn't have Button and all 
I see is SubmitField, so I tried this:
def StyleTwoForm(choices, *args, **kwargs):
	class StaticForm(FlaskForm):
		pass
	print("Here8")
	StaticForm.submitFields = [SubmitField(choice) for choice in choices]
	return StaticForm()

Bypassing WTForms I can just do this in template:
{% for choice in question.question_choices %}
                            <button id="btn0" class="btn">{{choice.choice_content}}</button>
                        {% endfor %}

That's a bit crap though, can I do this through WTForms with a list of SubmitField? I tried this 
in template:

{% for submit in form.submitFields %}
                            submit
                        {% endfor %}

But all I'm getting in HTML instead of a submit field I'm getting a
<UnboundField(SubmitField, ((1, 'Taiwanese'),), {})>

Am I missing something?

Related articles

Dynamic WTForms and multiple button/submitfields (all 5) RSS
├─ THIS   Sat 16th May, 2:33pm, Nicholas T.
├─ reply 1   Sat 16th May, 3:54pm, Timothy F.
├─ reply 2   Sat 16th May, 6:00pm, Nicholas T.  O.P.
├─ reply 3   Sat 16th May, 10:08pm, Timothy F.
└─ reply 4   Sun 17th May, 12:59pm, Nicholas T.  O.P.
This Page


Program written by: [email protected]
Feedback welcome
Last modified:  8:27am May 24 2020