Slider widget.

1,538 views
Skip to first unread message

Ted Ahn

unread,
Oct 12, 2020, 12:58:44 PM10/12/20
to oTree help & discussion
Hello,

I am looking for a way to set up a slider widget. From the earlier discussions in the forum, I see that some people set the widget as:

XXX = models.IntegerField(
label= "What income did you get from your photography profession in the past year? Please respond in",
min = 0, max = 100000,
initial = 0,
"widget = widgets.Slider(attrs={'step': '500.00'})

However, if I go to the Player field right now, I do not see a Slider widget but only radio button features. How can I add a slider widget as above?

Thanks!


Ted

Chris @ oTree

unread,
Oct 12, 2020, 1:26:26 PM10/12/20
to oTree help & discussion
See here: https://otree.readthedocs.io/en/latest/forms.html#raw-html-example-slider

I recommend that approach rather than using the Slider widget.

Ted Ahn

unread,
Oct 12, 2020, 2:27:09 PM10/12/20
to oTree help & discussion
Thank you for your response, Chris!

If I use HTML + Javascript, how do I save the responses from participants? Say, if I use raw HTML codes on the document to make sliders, are participants' response automatically saved?

Thanks!


Best,
Ted

2020년 10월 12일 월요일 오후 12시 26분 26초 UTC-5에 Chris @ oTree님이 작성:

June Nguyen

unread,
Jun 7, 2021, 5:21:07 AM6/7/21
to oTree help & discussion
Hi,

I'm having the same question. How do I save slider response from HTML code to python otree so that I can show participants their response in another html page?

Thanks,
June

Max R. P. Grossmann

unread,
Jun 7, 2021, 5:25:36 AM6/7/21
to June Nguyen, oTree help & discussion
Hi all,

Any <input> field in HTML which has the name="FIELDNAME HERE" of your field will be recorded by oTree.

E.g.

<input type="range" name="myfield" min="0" max="4" value="0" step="0.01" class="form-range">

will be recorded in the field "myfield", which could be a FloatField.

One can even use something like this:

<input type="hidden" name="myfield">

Useful for JavaScript slider validation and the like (such as optional sliders). The value of this hidden input will be recorded by oTree as if it were an ordinary input.

Best,

Max
> --
> You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/ede47dd9-3861-413d-944e-0ec882c82707n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages