Skip to content

Instantly share code, notes, and snippets.

@ajford
Created May 19, 2016 19:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajford/564cd00b361a08630b626d24408206b4 to your computer and use it in GitHub Desktop.
Save ajford/564cd00b361a08630b626d24408206b4 to your computer and use it in GitHub Desktop.
Example demonstrating the use of WTForms keyword arguments to set disabled state
import wtforms as wtf
class MyForm(wtf.Form):
sel = wtf.SelectField('Select',choices=[(1,'One'),(2,'Two')],
default=1)
class MyDisabledForm(wtf.Form):
sel1 = wtf.SelectField('Select',choices=[(1,'One'),(2,'Two')],
default=1,render_kw={'disabled':'disabled'})
sel2 = wtf.SelectField('Select',choices=[(1,'One'),(2,'Two')],
default=1,render_kw={'disabled':''})
sel3 = wtf.SelectField('Select',choices=[(1,'One'),(2,'Two')],
default=1,render_kw={'disabled':'false'})
if __name__ == "__main__":
tfile = open('./test.html','wb')
t2file = open('./test2.html','wb')
myform = MyForm()
mydform = MyDisabledForm()
tfile.write("<html><body>{}</body></html>".format(
"<br>".join([f() for f in mydform])))
t2file.write("<html><body>{}<br>{}</body></html>".format(
myform.sel(),myform.sel(disabled="disabled")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment