#1 by Janina (edited )
Hi, do you know whether there exists any possibility to increase the size of the input field in the HTML-page, if it is defined in 'form-fields'? Or does any workaround exist? Cheers Janina
#2
by
BonnEconLab
Hi Janina,
What type of input are you referring to?
I imagine that your use case is an open-ended question for which a <textarea> field would be appropriate. If this is so, you can do the following:
Say, your formfield is defined as
comment = models.LongStringField(
label="",
blank=False,
)
See https://otree.readthedocs.io/en/latest/models.html#field-types: A LongStringField is “for long text strings; its form widget is a multi-line textarea.”
Then, instead of
{% formfield player.comment %}
you can include, say,
<textarea class="form-control" rows="7" id="id_comment" name="comment"></textarea>
{% formfield_errors 'comment' %}
in your HTML template. The “rows” attribute determines the vertical extent of the input field. There is also a “cols” attribute for the field’s width: https://www.w3schools.com/tags/tag_textarea.asp. Importantly, the “name” attribute has to be equal to the formfield’s name (which is “comment” in this example).
See https://otree.readthedocs.io/en/latest/forms.html#raw-html-widgets and https://otree.readthedocs.io/en/latest/forms.html#customizing-a-field-s-appearance.
Best,
Holger
#3 by Janina
Hi Holger, it worked. Thank you very much for your help!! Best, Janina