Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WTForms-How to prepopulate a textarea field?

Tags:

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?

like image 764
Rasmus Avatar asked Feb 25 '11 12:02

Rasmus


2 Answers

You can do it before rendering, something like:

form.content.data = 'please type content' 

I'm new to WTForms though.

like image 186
hilquias Avatar answered Sep 21 '22 20:09

hilquias


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.

like image 24
Sean Vieira Avatar answered Sep 23 '22 20:09

Sean Vieira