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

前端 未结 9 1920
暗喜
暗喜 2021-02-18 22:40

Constructing a wtforms\' TextAreaField is something like this:

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


        
9条回答
  •  南旧
    南旧 (楼主)
    2021-02-18 23:17

    I was able to modify the rows and columns via the render_kw tag on the python forms page. When I first saw the definition of this on WTForm's website, I didn't know what it did until seeing other people's examples of using this to modify the class of the form element. So their definition just confused me until I started experimenting with it.

    render_kw (dict) – If provided, a dictionary which provides default keywords that will be given to the widget at render time. - https://wtforms.readthedocs.io/en/stable/fields.html

    I used this on my forms page.

    current_templates_in_library = TextAreaField('current_templates_in_library', render_kw={'rows':'4'})
    

    To add multiple tags and values, just separate them with a comma like this.

    render_kw={'class':'myclass','rows':'4'}
    

    Then this was rendered in the HTML. Notice the "rows" attribute there that was added.

    
    

提交回复
热议问题