How can I display the unit next to formfields? (in html)

198 views
Skip to first unread message

Klara

unread,
May 31, 2021, 5:39:20 AM5/31/21
to oTree help & discussion
Hi everyone, I am new here (and also to otree) and hopefully doing this right.

I have spent a long time trying to figure this out, even if it seems so "small" I would appreciate any help!

I am asking about "formfields":

1. want to display a unit next to a formfield, like "points" here: https://ibsen-otree-docs.ibsen-h2020.eu/_images/Sz34h7d.png

I tried:
<nobr>{% formfield field %}  % </nobr>

but it wont do the trick and just jumps to the next row and wont show up next to it.

2. I want participants to only be able to enter "40" into the formfield. I did that with the min/max option, however I dont want the formfield to tell participants "Please enter a number smaller than 40". I tried costumizing this (see below) but nothing changed - so I was wondering whether someone has a suggestion on how to adjust the error message or at least stop otree from dispaying the default one?

The part in red is what I added to my models.py (we need to use an older otree version):
class Player(BasePlayer):
ContributionA = models.IntegerField(
label="Please state the contribution of A in % (rounded to the nearest integer):"
)
contributiona1 = models.IntegerField(
label="Please state the contribution of A in % (rounded to the nearest integer):",
min=40 , max=40
)
def contributiona1_error_message(player, value):
print('This is incorrect')
if value != 40:
return 'Please calculate the contribution of team mate A again'

however, as I said, nothing happened - I am not sure whether this approach is even possible..

thanks for any suggestions!
Klara

Chris @ oTree

unread,
Jun 3, 2021, 6:30:46 AM6/3/21
to oTree help & discussion
On Monday, May 31, 2021 at 3:39:20 AM UTC-6 Klara wrote:
Hi everyone, I am new here (and also to otree) and hopefully doing this right.

I have spent a long time trying to figure this out, even if it seems so "small" I would appreciate any help!

I am asking about "formfields":

1. want to display a unit next to a formfield, like "points" here: https://ibsen-otree-docs.ibsen-h2020.eu/_images/Sz34h7d.png


If you want it to say "points", then simply use a CurrencyField rather than IntegerField. 
If you want it to say something else, then rather than using {% formfield %} you should use manual form layout or raw HTML.
By the way, that ibsen-otree-docs site is not the oTree official documentation, it is some out-of-date version of a software derived from otree.

 
I tried:
<nobr>{% formfield field %}  % </nobr>

but it wont do the trick and just jumps to the next row and wont show up next to it.

2. I want participants to only be able to enter "40" into the formfield. I did that with the min/max option, however I dont want the formfield to tell participants "Please enter a number smaller than 40". I tried costumizing this (see below) but nothing changed - so I was wondering whether someone has a suggestion on how to adjust the error message or at least stop otree from dispaying the default one?

Remove this: min=40 , max=40 
Reply all
Reply to author
Forward
0 new messages