I am currently rendering several Flask fields (SelectFields, InputFields) using the following jinja2 template:
<div>{{ wtf.form_field(form.blockingProbability) }}</div>
This results in the following format:
I'd like to control the width of the dropdown list (narrower width would look more natural, methinks), but (unsurprisingly) when I try doing this by controlling the div
width, the entire field, including the label is constrained and the label text wraps around.
Is there any way to control the width of the dropdown field (and other input fields), while keeping the width of the label intact (unwrapped)?
This worked for me
jinja2 template:
<div style="width: 50%">
{{ form1.language.label }}
</div>
<div style="width: 25%">
{{ form1.language }}
</div>
This is the form1 class:
class myForm(Form):
language = SelectField(u'Programming Language', choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')])
This should work too and it also maintain the visual consistency with other fields' widths:
<div>{{ wtf.form_field(form.blockingProbability, horizontal_columns=('lg', 2, 4)) }}</div>
The last value - 4
- in horizontal_columns
sets the width of the input field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With