oTree Forum >

Skip the task button

#1 by FEDx

Hi,
I would like to create a button that allows subjects to skip the task and go directly to the next one (not the next page but the app).
I thought to create something using the following:
<input type="button" name="Skip the task" onclick="clickFunction()"> 

But how can I populate the click function correctly?

Thanks

#2 by Chris_oTree

Make a field like this:

skipped_task = models.BooleanField()

Add that to the form_fields, then do:

<button name="skipped_task" value="1">Skip the task</button>

Then:

def app_after_this_page(player, upcoming_apps):
    if player.skipped_task:
        return upcoming_apps[0]

#3 by BonnEconLab

I would suggest to use

skipped_task = models.BooleanField(initial=False, blank=True)

The attribute blank=True will also be necessary for the form fields that participants can actually skip. Moreover, field_maybe_none (see https://otree.readthedocs.io/en/latest/misc/tips_and_tricks.html#field-maybe-none) may become necessary down the road.

To make the “Skip” button stand out, one could format it via

<button name="skipped_task" value="1" class="btn btn-danger">Skip the task</button>

#4 by FEDx

Thank you very much!

Write a reply

Set forum username