Created
May 19, 2016 19:14
-
-
Save ajford/564cd00b361a08630b626d24408206b4 to your computer and use it in GitHub Desktop.
Example demonstrating the use of WTForms keyword arguments to set disabled state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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