I have a WTF SelectField, and I'm trying to store the name of the user's choice for display on another page.
Given that my form is
choice = SelectField('Choice', choices=[('cho_1', 'Choice One'), ('cho2', 'Choice Two')])
I understand that
self.choice = form.choice.data
will get me the user's choice (say, cho_1), but how do I get the value ("Choice One")? I feel like it's something simple with dicts, but various attempts plus googling/searching SO haven't helped so far.
Thanks to Ashish Nitin Patil for directing me to here.
I needed to transform the 'choices' into a dict, then get the value for key form.data, thus:
value = dict(form.choice.choices).get(form.choice.data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With