Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify rows and columns of a <textarea > tag using wtforms

Tags:

python

wtforms

Constructing a wtforms' TextAreaField is something like this:

content = wtf.TextAreaField('Content', id="content-area", validators=[validators.Required()])

How can I specify the number of rows and columns associated with this textarea?

like image 805
Kevin Le - Khnle Avatar asked Feb 08 '11 07:02

Kevin Le - Khnle


2 Answers

You are not supposed to do it in the place where you declare the widget. You have do it in the template. For eg:

{{form.content(rows='50',cols='100')}}

Need to ensure the rows and cols are specified as a string.

like image 200
Rasmus Avatar answered Oct 05 '22 05:10

Rasmus


Much simpler; use render_kw argument when creating the field:

port = IntegerField(u"HTTP port", validators=[DataRequired(), NumberRange(1025, 65535)], render_kw={'class': 'form-control'})
mytextarea = TextAreaField(u"Content", render_kw={'class': 'form-control', 'rows': 5})

And then render the file:

{{ field() }}
like image 27
okelet Avatar answered Oct 05 '22 03:10

okelet