Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Flask WTForms: How can I disable a field dynamically in a view?

I've been able to implement this change to create Field which is disabled in WTForms. How would I selectively disable a field in my view before rendering it?

like image 742
sixarm Avatar asked May 07 '13 16:05

sixarm


2 Answers

vim forms.py:

add_time = DateTimeField(

    '添加时间',
    format='%Y-%m-%d %H:%M:%S',
    default=datetime.datetime.now(),
    # I use bs3,and it well add input an attribute disabled
    render_kw={'disabled':''},
    validators=[DataRequired()],
)
like image 87
fengling 姚 Avatar answered Oct 28 '22 10:10

fengling 姚


It's almost as @Bibhas proposed. If I understand this correctly and you want to disable a field through the html disabled attribute, then the following worked for me:

form.field(disabled=True)

This answer might be a bit late, but if any one else has this problem it might help.

like image 10
René Jahn Avatar answered Oct 28 '22 11:10

René Jahn