Problems with {{ form.my_field.errors }} in oTree Lite

534 views
Skip to first unread message

Daniel Frey

unread,
Mar 3, 2021, 9:05:01 AM3/3/21
to oTree help & discussion
Hello everybody

I found a problem with the formfields using IntegerFields with choices.

I created a survey-question with 10 different options in  as follows: 

class Player(BasePlayer):
  risk = models.IntegerField(widget=widgets.RadioSelect,
    label="Please indicate your answer on the following scale: 1 means: not at all willing to take risks, 10 means: very willing to take risks.",
    choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

I want to present the choices in a html-table, like this:

risks.jpg

If I test it, a message on the Debug info appears:

The form field risk has errors, but its error message is not being displayed, possibly because you did not include the field in the page. There are 2 ways to fix this:

  1. Include the field with the formfield tag, e.g. {% formfield "risk" %}
  2. If you are not using formfield but are instead writing the raw HTML for the form input, remember to include {{ form.risk.errors }} somewhere in your page's HTML.
As I'm not using the {% formfield 'risk' %}-tag, I included {{ form.risk.errors }} in the html-page.

Then, something very weird happens: At the place I included the error (right at the end, after </table>), two brackets appear on the html-page: 

risks2.jpg

I believe this is a bug in the latest oTree version, right?

Chris @ oTree

unread,
Mar 3, 2021, 11:01:42 AM3/3/21
to Daniel Frey, oTree help & discussion
See here: https://otree.readthedocs.io/en/latest/misc/otreelite.html#forms

Sent from my phone

On Mar 3, 2021, at 10:05 PM, Daniel Frey <danie...@iop.unibe.ch> wrote:

Hello everybody

I found a problem with the formfields using IntegerFields with choices.

I created a survey-question with 10 different options in  as follows: 

class Player(BasePlayer):
  risk = models.IntegerField(widget=widgets.RadioSelect,
    label="Please indicate your answer on the following scale: 1 means: not at all willing to take risks, 10 means: very willing to take risks.",
    choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

I want to present the choices in a html-table, like this:

<risks.jpg>


If I test it, a message on the Debug info appears:

The form field risk has errors, but its error message is not being displayed, possibly because you did not include the field in the page. There are 2 ways to fix this:

  1. Include the field with the formfield tag, e.g. {% formfield "risk" %}
  2. If you are not using formfield but are instead writing the raw HTML for the form input, remember to include {{ form.risk.errors }} somewhere in your page's HTML.
As I'm not using the {% formfield 'risk' %}-tag, I included {{ form.risk.errors }} in the html-page.

Then, something very weird happens: At the place I included the error (right at the end, after </table>), two brackets appear on the html-page: 

<risks2.jpg>


I believe this is a bug in the latest oTree version, right?

--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/b7787960-87f8-4ddd-908b-6edcb66813f4n%40googlegroups.com.
<risks2.jpg>
<risks.jpg>

Daniel Frey

unread,
Mar 3, 2021, 1:50:05 PM3/3/21
to oTree help & discussion

That works, thanks!
Reply all
Reply to author
Forward
0 new messages