Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im creating a form using flask, wtforms and jinja. Im trying to figure out how can my radiofields have pre-checked values based on data from db? For example I have a db of various merchants that need to be contacted. The fact that merchant has been contacted is shown in a radiobutton field:

contacted = RadioField('Has merchant been contacted', choices=[('No', 'No'), ('Yes', 'Yes')])

Whenever this form is saved, the value 'No' or 'Yes' gets passed as a string to table merchants column contact

The value gets saved successfully, but each time the concrete merchants view is visited again the radiobutton is not checked with the previously saved value. This means that the apps user does not see the current status of the merchant.contact column value (meaning he doesnt know if the merchant was or wasnt contacted)

I tried adding the merchant.contact value in the value attribute in jinja templates but it didnt work:

{{result_form.contacts(class='form-check-input', type='radio', value=merchant.contact)}}

Any ideas how to make the radiobutton field be checked based on a value from a database?

question from:https://stackoverflow.com/questions/66063083/flask-wtforms-radiofield-value-checked-based-on-data-from-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
532 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...