WTForms-How to prepopulate a textarea field?


Question

Hi I have been trying to pepopulate a textareafield using something like this in the template.

{{form.content(value="please type content")}}

This works when the field is textfield primarily because the html accepts value for <input type="text"> but the same does not work for textarea... Can someone please help me with this?

1
18
2/25/2011 8:33:48 PM

Accepted Answer

For textarea widgets, you set the default content with the default argument in your field constructors.

class YourForm(Form):
    your_text_area = TextAreaField("TextArea", default="please add content")

Then when you render:

{{form.content()}}

WTForms will render the default text. I have not been able to find a way to specify default text for the text area at render time.

16
2/25/2011 9:02:00 PM

You can do it before rendering, something like:

form.content.data = 'please type content'

I'm new to WTForms though.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon