oTree Forum >

{{ form.myfield.0 }} Help

#1 by PatrickT

Good afternoon,

I am trying to insert formfield choices into an HTML table. I came across the following forum post:
https://www.otreehub.com/forum/72/

I have a variable named "Effort" defined like so:
Effort = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], label='Please select how much effort you would like to provide', max=7, min=0, widget=widgets.RadioSelectHorizontal)

So, I tried to use {{ form.Effort.1}}, {{ form.Effort.2}}, etc. but every time I get  "Cannot resolve the variable 'form.Effort.7'"

Any help would be appreciated.

#2 by ccrabbe

Hi PatrickT -

The oTree documentation has a section for putting radio buttons in tables:

https://otree.readthedocs.io/en/latest/forms.html#example-radio-buttons-in-tables-and-other-custom-layouts

And if that doesn't specifically do what you want, the section below it about "Raw HTML widgets" explains how to just code up any html input to snap into oTree's expected field naming conventions so that you can use any html you want to submit a form with the structure oTree expects.

Thanks,
--Chris

#3 by PatrickT

Thank you. I ended up downloading cursor and with the help of the Otree AI assistant I inserted these loops into my table and now the code works fine:

    {{ for choice in form.Effort }}
      {{ if forloop.counter == 1 }}
        {{ choice }}
      {{ endif }}
    {{ endfor }}

#4 by Chris_oTree

good. also make sure to install the otree plugin for Cursor: https://www.otreehub.com/forum/1383/
they kind of need to be used together.

#5 by PatrickT

I did! They work good together. Not perfect, but much better than using a generic LLM like chatgpt for otree help

Write a reply

Set forum username