2

I was wondering if it is possible to have a multiple choice question in otree. Something like radio button but that lets you choose more than one thing. What I'm thinking of is something like:

Question: The following list of statements contains three correct statements and three false statements. Please select the three correct statements:

  • Statement 1
  • Statement 2
  • Statement 3
  • Statement 4
  • Statement 5
  • Statement 6
IonicSolutions
  • 2,559
  • 1
  • 18
  • 31
TEC
  • 53
  • 7
  • yes, it does. See here: https://groups.google.com/d/msg/otree/CLmiH595UDM/QnPSQyf-BAAJ - it's a link to official oTree group forum where this has been discussed. In fact it is just a simple django Multiple choice select widget – Philipp Chapkovski Jul 19 '18 at 10:29

1 Answers1

1

You can use otree_models.models.MultipleChoiceFormField for this purpose, as sketched out in the following:

In models.py:

from otree.api import BasePlayer
from otree_tools.models import fields as tool_models

class Player(BasePlayer):

    correct_statements = tool_models.MultipleChoiceModelField(label="Please select the three correct statements",
                                                              min_choices=3, max_choices=3)

In pages.py:

from ._bultin import Page

class ExamplePage(Page):

    form_model = "player"
    form_fields = ["correct_statements"]

    def correct_statements_choices(self):
         """Return the list of statements to choose from."""
         return ["Statement 1", "Statement 2", "Statement 3",
                 "Statement 4", "Statement 5", "Statement 6"]

In ExamplePage.html, simply include the form field:

{% extends "global/Page.html" %}
{% load otree %}

{% block content %}
The following list of statements contains three correct statements and three false statements. 

{% formfield player.correct_statements %}

{% next_button %}

{% endblock %}
IonicSolutions
  • 2,559
  • 1
  • 18
  • 31