oTree Forum >

Random order of radio button answering choices

#1 by m_hr3 (edited )

EDIT: 
I managed to do it as follows:

Question_1 = models.BooleanField(choices=random.sample([[False, 'No'], [True, 'Yes']], 2), blank=True)


Hello, 

I have several formfields with radio buttons where participants answer the questions with 'yes' or 'no'. 

Is it possible to have location of the 'yes' and 'no' on the web page randomised? Right now the radio button for 'yes' is always above 'no'. I'd like for the button location to vary randomly: sometimes 'yes' on top and sometimes 'no'. Is there a way to do this? 

Thank you very much for any advice. 
Maria

#2 by gr0ssmann

I don't think your solution works.

I would have recommended looking at https://otree.readthedocs.io/en/self/forms.html#field-name-choices but for some reason this doesn't work anymore. This gives merely an empty <input> field and the method called fruit_choices is never invoked. @Chris, could you perhaps look at this?

#3 by Chris_oTree

That is the documentation for the old self-format.

#4 by gr0ssmann

Oops, thanks! That's true.

In that case, I would recommend using https://otree.readthedocs.io/en/latest/forms.html#field-name-choices

#5 by m_hr3

Thanks for your replies.

My solution above with random.sample seems to work and do the job.

#6 by gr0ssmann

It is if you are fine with everyone having the same (random) order.

Write a reply

Set forum username