Hello,
If you just want to ask each participant a different question and a text input for an answer, then you may only need one page where the question changes. You can do that for example by assigning each participant a StringField variable which contains the question and display it on the page with {{ player.variable_name }}
.
If your treatments are only one or two pages but will differ greatly in the interface and the kind of inputs you expect (dropdowns, numbers, texts, buttons): You could make a more complicated template where all those inputs are custom html elements that are hidden by default and then display the question and an appropriate element based on the participant id. Alternatively since you say you’re new to programming you can just make all the different 48 pages and only display the one you want to to the participant with is_displayed()
- https://otree.readthedocs.io/en/latest/pages.html#is-displayed
Alternatively, either if you meant treatments as more complex series of pages or actual full treatments, or if you find the following solution better: You could make 48 actual treatments in otree then first have a small ‘intro treatment’ for everyone, where you use the new app_after_this_page()
- https://otree.readthedocs.io/en/latest/pages.html?highlight=next#app-after-this-page - to select the appropriate treatment for each participant.
Hope that gives you a few ideas and good luck. :)
Rok
Yes, what you want is exactly what I’ve described in the last reply.
Instead of the stuff in your second picture, copy in this:
<button id="close-image" onclick="incrementValue(1)"><img src={% static "treatment1/5.PNG" %}/></button>
<button id="close-image" onclick="incrementValue(2)"><img src={% static "treatment1/6.PNG" %}/></button>
<button id="close-image" onclick="incrementValue(3)"><img src={% static "treatment1/7.PNG" %}/></button>
<input type="hidden" name="verde" id="field_1" value="0"/>
<input type="hidden" name="amarillo" id="field_2" value="0"/>
<input type="hidden" name="rojo" id="field_3" value="0"/>
<script>
function incrementValue(button_number)
{
// piece together id of the field
id = 'field_'+button_number;
// get current value of the field
var value = parseInt(document.getElementById(id).value, 10);
// if value is not a number, set it to 0
value = isNaN(value) ? 0 : value;
// increase value
value++;
// set value to the field
document.getElementById(id).value = value;
}
</script>
Rok
Additionally, you’ll need to set your page’s form model and fields (in the page where you're showing your 3 buttons):
class MyPage(Page):
form_model = 'player'
form_fields = [' verde', 'amarillo', 'rojo']
Also, your buttons should not have the same id. It will work but id’s are meant to be unique. If you need your buttons to have the same identifier for CSS, use class instead fo id, and change #close-image in yoru CSS to .close-image
Rok
whoops, there’s a space character in the form_fields above. Copy the following over your current form fields.
form_fields = ['verde', 'amarillo', 'rojo']
I’d rather keep helping you on here, in case it helps someone else in the future. :)
Let me know how it goes,
Rok
Yes, Thank you, it’s working now.
Very kind of you and your team.
Kind regards
Sent from Mail for Windows 10
--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/gWiz_EexLD0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/b507ec32-f4af-4526-a688-0309db0d4401n%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/d3156c6f-b928-40fc-907b-59db2d369c51n%40googlegroups.com.
Thank you Rok, I think this might work.
I’ll try this and will let you know.
“I'm not sure I follow on what is supposed to happen when you press the buttons. You would like to show two pages on a button press? Do you mean when you press a button you are redirected to certain otree page sequence, for example, button Masquefa takes you to MyPageOne then from that one to MyPageTwo, but if you press another button, Poetas Anonimos, you will instead continue to MyPageSeven and from that one to MyPageEight?”
This is exactly what I want to do.
Each button should show me 2 different pages.
For example if I press first button, It should show me 2 different pages.
Thank you once again.
Kind Regards!
Enviado desde Correo para Windows 10
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/671f5ef3-825b-4e1f-93ae-dfb2dded8105n%40googlegroups.com.
Hello Rok,
"
To achieve the above, you can use is_displayed() on the pages that you want to show to some participants and hide to others. So from the above example, you would put the is_displayed() function in pages MyPageOne, MyPageTwo, MyPageSeven, MyPageEight, and inside the function just check the appropriate player variable, like:
"
I've done this for all three different pages and I am getting this error.
As you can see in 5.png, I've created 3 buttons and then I've created 6 pages in total for these 3 buttons, (2 for each page)
When I click on any button, I get the error. As you can see in 7.png.
Also attaching you a screenshot of code of pages.py
Kindly let me know how to solve it. I am stuck here,
Kind Regards
Irtaza
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/671f5ef3-825b-4e1f-93ae-dfb2dded8105n%40googlegroups.com.
from otree.api import Currency as c, currency_range
from ._builtin import Page, WaitPage
from .models import Constants
class Page1(Page):
pass
class Page2(Page):
pass
class Page3(Page):
form_model = 'player'
form_fields = ['masquefa', 'poetas_anonimos',
'avenida_cataluña']
class Page4_masquefa(Page):
def is_displayed(self):
return self.player.masquefa > 0
class Page5_masquefa(Page):
form_model = 'player'
form_fields = ['salir', 'ver_datos', 'crear_alerta']
class Page4_poetas(Page):
def is_displayed(self):
return self.player.poetas_anonimos > 0
class Page5_poetas(Page):
form_model = 'player'
form_fields = ['salir', 'ver_datos', 'crear_alerta']
class Page4_avenida(Page):
def is_displayed(self):
return self.player.avenida_cataluña > 0
class Page5_avenida(Page):
form_model = 'player'
form_fields = ['salir', 'ver_datos', 'crear_alerta']
class Instrucciones(Page):
pass
class Results(Page):
pass
page_sequence = [
Page1,
Page2,
Page3,
Page4_masquefa,
Page5_masquefa,
Page4_poetas,
Page5_poetas,
Page4_avenida,
Page5_avenida,
]
It's not working.
Also attaching you code of models.py
from otree.api import (
models,
widgets,
BaseConstants,
BaseSubsession,
BaseGroup,
BasePlayer,
Currency as c,
currency_range,
)
import random
author = 'Irtaza Ali Ajmal'
doc = """
Emivasa Tratamiento 1
"""
class Constants(BaseConstants):
name_in_url = 'treatment1'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
masquefa = models.IntegerField()
poetas_anonimos = models.IntegerField()
avenida_cataluña = models.IntegerField()
salir = models.IntegerField()
ver_datos = models.IntegerField()
crear_alerta = models.IntegerField()
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/db157571-312d-456a-af69-766386042febn%40googlegroups.com.
Hello Rok,
So I am going to try to explain better.
Basically I have one app which in total has 9 pages. First 2 pages are just introduction where I show the images, then on the 3rd page there are 3 selection buttons which are
So here if we select First option one 3rd page"Masquefa" it should just show pages "Page4_masquefa and Page5_masquefa"
and if we select 2nd option "Poetas Anonimos" it should just show pages "Page4_poetas_anonimos and Page5_poetas_anonimos"
And same goes if we select 3rd option "Avenida Cataluña" it should just show pages Page4_avenida_cataluña and Page5_avenida_cataluña"
But here the problem is after I choose the button "Masquefa" on 3rd page, it takes me to "Page4_masquefa" which is correct but then I click on the next button to go to "Page5_masquefa"
The 5th page also has 3 buttons.
By pressing either of the buttons it should take me to next app which is a questionnaire, but unfortunately it's taking me to "Page5_poetas_anonimos" and then by pressing either of the three buttons it's taking me to "Page5_avenida_cataluña" and after that the whole apps ends.
Attaching you code of my pages.py and of modeld.py so you could have a look.
Kind Regards
Irtaza
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/db157571-312d-456a-af69-766386042febn%40googlegroups.com.
Thank you very much, it’s working now.
I just have 2 more doubts and hopefully you can help with them as well.
1st doubt:
So I am gonna have a button "salir" on some pages (3,4) (as you can see in the screenshots 1 and 2) and the function of this button should be that when it's pressed it should take me to next app.
How can I do that?
the button "salir" is in app "treatment1" and the next application is "questionarie_full".
The purpose of this button is whenever it's pressed, should skip the next pages of the app and take me to the next app directly.
2nd doubt:
I’ve 3 variables on the 5th page, so I want to record a specific number once either of the buttons is pressed. (Screenshot 3)
For example I want to store in the variables:
When someone presses the button “crear alerta” I want to store a value of 1
When someone presses the button “ver datos” I want to store value 5
And finally when someone presses the button “Salir” I want to store value of 10.
That’s the only 2 things left to complete my Project.
Attaching screenshots.
Kind Regards
Enviado desde Correo para Windows 10
De: Rok
Enviado: martes, 23 de marzo de 2021 14:31
Para: oTree help & discussion
Asunto: Re: [oTree] Re: Random Treatments
Hello,
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/a1d17b02-427d-463c-902d-7302d01dc009n%40googlegroups.com.
About the second issue, as you told me, it creates 3 new buttons as you’ll see in the screenshot.
But stores the values correctly, I want them to be hidden behind the images buttons.
Attaching you HTML file so you could take a look.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/083034cb-997c-4e8a-8737-5ea983d1fc6an%40googlegroups.com.
Dear Rok,
I've tried it how you said for rest of buttons too, but unfortunately it doesn't work.
Attaching a screenshot.
Kindly let me know what I am doing wrong.
Irtaza
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/7fa03f3d-5278-4be3-9e0e-11e4dce75b77n%40googlegroups.com.
Dear Rok,
I've tried it how you said for rest of buttons too, but unfortunately it doesn't work.
Attaching a screenshot.
Kindly let me know what I am doing wrong.
IrtazaTo view this discussion on the web, visit https://groups.google.com/d/msgid/otree/7fa03f3d-5278-4be3-9e0e-11e4dce75b77n%40googlegroups.com.
If I delete the hidden inputs, I get this error, even though it stores the value of the variable, but doesn't go to next page.
Irtaza
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/9cb0d926-b9e2-4635-ab36-059981b4ede0n%40googlegroups.com.
I’ve done it and I still get the same error, I’ve set all these 3 variables models.py to initial = 0.
If you want I can attach models.py, pages.py and one of HTML file.
Kind Regards
Irtaza
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/817043a1-d7cb-4ca9-8231-a1ebddb8fa9an%40googlegroups.com.
Thank you once again.
It worked with (blank=True)
Kind Regards
Irtaza Ali
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/0ca5cc7c-e112-4aa7-b0e0-b443a745b3fbn%40googlegroups.com.
Hello Rok,
Hope you are doing well.
I’ve some doubts about a payment app.
I was hoping maybe you could help.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/b3304288-613a-4b31-a741-914887cb46d8n%40googlegroups.com.