https://otree.readthedocs.io/en/latest/forms.html?highlight=checkbox#raw-html-widgets
Player class would look something like this:
class Player(BasePlayer):
choice1 = models.BooleanField(blank=True)
choice2 = models.BooleanField(blank=True)
# ... etc
Then in your template, you don’t use {% formfields %}, but instead write something like this:
<p>My first multiple choice question:</p>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="choice1">
<label class="form-check-label">
Text for choice 1
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="choice2">
<label class="form-check-label">
Text for choice 2
</label>
</div>
Since you’re not using {% formfields %} anymore, you can use {% formfield 'my_field' %} (or any other way of doing it from the linked docs above) to display your other input fields on this page.
You may want to include the code {% if form.my_field.errors %}{{ form.my_field.errors.0 }}{% endif %} somewhere on the page. It displays error messages if incorrect user inputs are submitted.
Hope that helps,
Rok
Hello, it seems I left a bit of code out in my original answer.
Make sure you have your BooleanFields set to initial=False, your inputs should have value=”True” and don’t forget to include the fields in your form_fields on the page where you display the checkboxes.
class Player(BasePlayer):
choice1 = models.BooleanField(blank=True, initial=False)
choice2 = models.BooleanField(blank=True, initial=False)
# ... etc
class MyInputPage(Page):
form_model = 'player'
form_fields = ['choice1', 'choice2']
<p>My first multiple choice question:</p>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="True" name="choice1">
<label class="form-check-label">
Text for choice 1
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="True" name="choice2">
<label class="form-check-label">
Text for choice 2
</label>
</div>
Best Regards,
Rok