Integer Field: Display labels rather than numbers

67 views
Skip to first unread message

Nanyin Yang

unread,
Sep 10, 2021, 6:32:41 PM9/10/21
to oTree help & discussion
Hi! I am new to oTree and would like to ask a question about displaying variables.

I am working on a project where I created some numeric variables using IntegerField while I hope that on html they could be displayed in texts rather than values. For example, after some calculation, if the variable takes value 1, then display "A". If the variable takes value 2, then display "B".

I know that I can create another string variable and define a mapping from values to texts. However, since I have many numeric variables in this program following the same display rule, creating string fields for every integer field can make the program very tedious. It would be more convenient if there is a way to set up such a display rule for all these numeric variables, for example, defining something in the "var_for_template" function??

Thank you!!

Nanyin
Message has been deleted

Chris @ oTree

unread,
Sep 10, 2021, 6:47:25 PM9/10/21
to oTree help & discussion
Set choices= like the low/medium/high example here: https://otree.readthedocs.io/en/latest/forms.html#choices
Then use the field_display method described in the same section.

Reply all
Reply to author
Forward
0 new messages