Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Form - enter button

edited May 2013 in OpenSesame

I'm trying to create a form in open sesame that is a question with three answer boxes. using the code bellow, to get from the first box to the second you have to press enter, then click the second box, type your response, press enter, click on the third box, type your answer, press enter, click next to move onto the next page. there is also a submit button, and if i make the accepts="yes" rather than no, pressing enter on that response moves onto the next page, which would be fine for the third question, but doesn't allow subjects to respond to the first two questions. we need to know the total time that the subject spends to answer all three questions

Ideally, I'd want to let subjects be able to move to the next box by clicking the tab button, or just having access to their mouse, because the enter then click thing is really annoying. Let me know if this is possible!


set margins "50;100;50;100"
set rows "1;1;1;1;1"
set spacing "20"
set cols "1;1;1"
set description "A generic form plug-in"
widget 0 0 3 1 label center="no" text="What were the [Target_Color] words?"
widget 0 1 1 1 text_input return_accepts="no" var="Word_01_Response"
widget 0 2 1 1 text_input return_accepts="no" var="Word_02_Response"
widget 0 3 1 1 text_input return_accepts="no" var="Word_03_Response"
widget 2 4 1 1 button text="Next"

Comments

  • edited 11:46AM

    ITA

    We will come back to you as soon as possible!

  • edited May 2013

    Hi,

    Sorry for the delay.

    There is also a submit button, and if I make the accepts="yes" rather than no, pressing enter on that response moves onto the next page, which would be fine for the third question, but doesn't allow subjects to respond to the first two.

    There is a trick to use this keyword argument to obtain the desired behaviour, namely a form in which the participant can go to the next box without having to make any mouse clicks.

    This works as follows. Instead of creating one form_base item, we wrap a loop item around three form_base items with a slightly OpenSesame script. (Still, for the participant this will look as one form.)

    More specifically:

    Firstly, create an experiment with an overview that looks something like this:

    image

    Secondly, enter the following scripts into the three form_base items (please see the comments for further explanation).

    form_base1: For the first text_input widget, set focus to 'yes', and set return_accepts to 'yes'. focus = 'yes' indicates that the participant can start typing in this box immediately (without having to click in it first). Don't specify anything yet for the other widgets yet (just draw them).

    set margins "50;100;50;100"
    set rows "1;1;1;1;1"
    set spacing "20"
    set cols "1;1;1"
    set description "A generic form plug-in"
    widget 0 0 3 1 label center="no" text="What were the [Target_Color] words?"
    widget 0 1 1 1 text_input focus="yes" return_accepts="yes" var="Word_01_Response"
    widget 0 2 1 1 text_input
    widget 0 3 1 1 text_input
    

    form_base2: For the second form_base, set focus and return_accepts to "yes" for the second text_input widget. For the first text_input widget, set the text to "Word_01_Response" (to keep the previously-given response on screen).

    set margins "50;100;50;100"
    set rows "1;1;1;1;1"
    set spacing "20"
    set cols "1;1;1"
    set description "A generic form plug-in"
    widget 0 0 3 1 label center="no" text="What were the [Target_Color] words?"
    widget 0 1 1 1 text_input text="[Word_01_Response]"
    widget 0 2 1 1 text_input focus="yes" return_accepts="yes" var="Word_02_Response"
    widget 0 3 1 1 text_input
    

    form_base3: For the last form_base item, fill both previous text input widgets with the given responses and set focus and return_accepts to 'yes' for the last item.

    set margins "50;100;50;100"
    set rows "1;1;1;1;1"
    set spacing "20"
    set cols "1;1;1"
    set description "A generic form plug-in"
    widget 0 0 3 1 label center="no" text="What were the [Target_Color] words?"
    widget 0 1 1 1 text_input text="[Word_01_Response]"
    widget 0 2 1 1 text_input text="[Word_02_Response]"
    widget 0 3 1 1 text_input focus="yes" return_accepts="yes" var="Word_03_Response"
    

    I uploaded a working example experiment here (download, change the extension from '.txt' into '.opensesame' and open as normally).

    I hope this helps! If you have any more questions, don't hesitate to ask them!

    Best,

    Lotje

  • edited June 2013

    Hi Lotje,

    Thanks so much for your help, it is so much better now! One question I can't figure out now is whether or not I can disable the tab function. As it is now, when participants press tab to go to the next box rather than return, the mouse appears and it is very hard to advance to the next page. It seems to work if I click on the first box and retype their answers, but if there is a way to just disable mouse/tab options completely that would be much easier.

    Thanks!

    Margaret

  • edited 11:46AM

    Sorry for the wait, I'll get back to you soon. ITA

  • edited June 2013

    Hi Margaret,

    The fact that pressing Tab defocuses a widget is built-in to the forms. The easiest way to nevertheless get the behavior that you need is probably to take control of the form widgets more directly. The script below implements the form described above in Python inline script.

    Essentially, the script doesn't run the form as a whole, but selectively activates the three text_input widgets. Normally, a form would show a mouse when you press Tab while in a text_input, but the script shown below will simply advance to the next widget when Tab is pressed. The script is explained in more detail in the code comments.

    This approach is more complicated than using the form_base plug-in, but it offers more flexibility. Also, it allows you to pack the whole form into one script, insteed of three separate items.

    For more information, see also:


    # Import the widgets library
    from libopensesame import widgets
    
    # Create a form
    form = widgets.form(self.experiment, cols=[1,1,1], rows=[1,1,1,1,1],
        margins=(50,100,50,100), spacing=20)
    
    # Create widgets
    question_text = 'What were the %s words?' % self.get('targetColor')
    question_label = widgets.label(form, text=question_text)
    input1 = widgets.text_input(form, return_accepts=True, var='Word_01_Response')
    input2 = widgets.text_input(form, return_accepts=True, var='Word_02_Response')
    input3 = widgets.text_input(form, return_accepts=True, var='Word_03_Response')
    
    # Add the widgets to the form.
    form.set_widget(question_label, (0,0), colspan=3)
    form.set_widget(input1, (0,1))
    form.set_widget(input2, (0,2))
    form.set_widget(input3, (0,3))
    
    # Reset the variables!
    exp.set('Word_01_Response', '')
    exp.set('Word_02_Response', '')
    exp.set('Word_03_Response', '')
    
    # Bypass the form, and activate the input widgets directly, by mimicking
    # mouse clicks. Pressing either tab or return will advance to the next widget.
    input1.on_mouse_click((0,0))
    input2.on_mouse_click((0,0))
    input3.on_mouse_click((0,0))
    
    # Optionally, you can give the user a second chance to fill in missed fields
    check = True # Set to False to deactivate checking
    if check and self.get('Word_01_Response') == '':
        input1.on_mouse_click((0,0))
    if check and self.get('Word_02_Response') == '':
        input2.on_mouse_click((0,0))
    if check and self.get('Word_03_Response') == '':
        input3.on_mouse_click((0,0))
    

    Cheers!
    Sebastiaan

Sign In or Register to comment.