Reputation: 363
Using wtforms I am trying to format the following form. So I have evrything working but I do not need the html table which 'FormField' gets wrapped in - so how to bypass/override that?
class WeekdayHoursForm(BaseForm):
hours = [(str(x+1), str(x+1)) for x in range(12)]
mins=[('00',':00'),('15',':15'),('30',':30'),('45',':45')]
fromHour = SelectField('',choices=hours)
fromMin = SelectField('',choices=mins)
toHour = SelectField('',choices=hours)
toMin = SelectField('',choices=mins)
closed = BooleanField('Closed','0')
class AddListingForm(BaseForm):
monday = FormField(WeekdayHoursForm)
tuesday = FormField(WeekdayHoursForm)
etc...
My View
<div class="wrapper-block weekday" id="mon">
{{ form.monday.label }} {{ form.monday() }}
</div>
<div class="wrapper-block weekday" id="tues">
{{ form.tuesday.label }} {{ form.tuesday() }}
</div>
I have omitted the generated HTML but I can paste it in if needed - I am aware wtforms FormField uses a 'TableWidget' but I dont know where to set this to 'with_table_tag = False'
?
Upvotes: 1
Views: 1527
Reputation: 159985
Every wtforms.fields.Field
subclass takes a keyword argument named widget
that can be used to override the rendering of the field. You can read more about the available WTForms widgets in their docs.
If you just wanted to use a list rather than a table you could use the built in ListWidget:
# ... snip ...
class AddListingForm(BaseForm):
monday = FormField(WeekdayHoursForm, widget=ListWidget)
tuesday = FormField(WeekdayHoursForm, widget=ListWidget)
Upvotes: 1