difficulties calling getTextInput on elements within the same trial and reg exp

PennController for IBEX Forums Support difficulties calling getTextInput on elements within the same trial and reg exp

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8383
    kavita thomas
    Participant

    Hi Jeremy,

    I am getting the following errors when I try and use getTextInput in a wait command while testing that the TextInput string matches a regular expression:
    16:9:0] Attempted to get an invalid element;;TextInput (newTrial: 1-experiment)
    [16:9:0] Attempted to get an invalid element;;TextInput (newTrial: 1-experiment)

    I’m trying to make sure that participants enter something for some of the key TextInput boxes, ex. name in the Intro trial and a judgment (G/U/DK) for the GJTs in the experiment trials. The easiest way I found to do this was to use getTextInput with reg.exp. matching in a wait(). I hope this is a reasonable way to do this.

    I’ve based the code on what I found in the manuals. The button for next page in the experiment trial doesn’t show up either, which is strange. Do you know why that’s happening?

    Also, would you recommend putting all GJT items into the experiment trial rather than creating a number of separate GJT items as separate trials?

    Here’s the demo link: https://farm.pcibex.net/r/Hjdxdc/

    Any help on this would be very much appreciated! At one point I even bounced from the intro trial to a ‘sending results to the server’ screen despite not having that newText element anywhere in my code, which was very strange.

    Thanks very much in advance!
    Kavita Thomas

    Here’s my main.js:

    PennController.ResetPrefix(null)
    //DebugOff()
    // Show the intro page with instructions
    // then all the 'experiment' trials, then send the results and finally show the trial labeled 'end'
    Sequence( "intro", "experiment", "send" , "end" )
    
    Header( /* void */ )
        // This .log command will apply to all trials
        .log( "ID" , GetURLParameter("id") ) // Append the "ID" URL parameter to each result line
    
    
    newTrial("intro",
      defaultText.center().print()
        ,
    
      newText("Welcome", "Welcome to the pretest of the HT22 written corrective feedback study! This quiz aims to find out more about your language learning background and grammar knowledge so your learning progress can be tracked through the study.")
        .center()
        .print()
    ,
      newText("EnterName", "Please start by entering your first and last name. Note that your results will be anonymized in the study and only you and me - Kavita Thomas, the researcher -  will have access to them. Please type your first and last name in the box below.")
        .center()
           .print()
           ,
    
       
        newTextInput("name","")
            .center()
            .lines(0)
            .size(600, 50)
            .print()
             .log()
        ,
    
    
        newButton("start", "Start the Test")
           .print()
           //.wait()
           .wait(getTextInput("name").test.text(/.+/) ) 
            
    )
    
    newTrial("experiment",
        newText("Instructions", "You will now read a sentence in English and need to judge whether you think the sentence is grammatically correct or not. Here you are not interested in the content or words or punctuation, just the form. After you decide whether the sentence is ungrammatical or not, please indicate for ungrammatical sentences how you would fix them so that they become grammatical.")
            .center()
           .print()
           ,
        newText("Example", "For example, if you read the sentence The cat chased mouse, you would click on the Ungrammatical button and then type a correction into the box: the mouse.")   
           .center()
           .print()
           ,
        
        newText("D1", "distractor sentence 1.")
           .center()
           .bold()
           .print()
           ,
        newText("instructions2", "Please type G if you think the above sentence is grammatically correct, U if you think it is not grammatically correct or DK if you don't know:")
            .center()
            .print()
            ,
        newTextInput("d1GJT", "")   
            .center()
            .lines()
            .size(600, 50)
            .print()
            .log()
            ,
       newText("CorrectionInstruction", "If you think the sentence above is ungrammatical, please fix the grammar mistake by typing the correct form in the box below:")
            .center()
            .print()
        ,
        newTextInput("correctionD1","")
            .center()
            .lines(0)
            .size(600, 50)
            .print()
            .log()
        ,
        newText("NextPage", "Once you have answered the above questions please click Next below to go to the next question.")
            .center()
            .print()
        ,
        newButton("nextQ", "Next Question")
            .print()
            .wait(getTextInput("d1GJT").test.text(/.+/) ) 
            //([A-Z]|[a-z])+/) )
    )    
    
    
    // Send the results
    SendResults("send")
    
    newTrial("end",
        exitFullscreen()
        ,
          newText("thanks")
            .center()
            .print()
        ,
     
        // Wait on this page forever
        newButton().wait()
    )
    .setOption("countsForProgressBar",false)
    #8385
    Jeremy
    Keymaster

    Hi Kavita,

    I think those errors came from a previous version of the script, maybe the latest changes failed to be saved when you tested the experiment. When I test the experiment at the link you provided, I see no errors, and same thing if I create a new project and paste the code from your message. Everything behaves as expected, namely clicks on the buttons only validate the wait commands if the referenced TextInput element have some text in them

    Also, would you recommend putting all GJT items into the experiment trial rather than creating a number of separate GJT items as separate trials?

    This is entirely your call, but what I would recommend is try to find some recurring pattern and avoid manually typing repeating commands. For example, if you decide to create separate trials, you could list the details of each trial in a table (say, gjt.csv) and use Template, eg:

    Template( "gjt.csv" ,
      newTrial("experiment",
        defaultText.center().print()
        ,
        newText("Instructions", "You will now read a sentence in English and need to judge whether you think the sentence is grammatically correct or not. Here you are not interested in the content or words or punctuation, just the form. After you decide whether the sentence is ungrammatical or not, please indicate for ungrammatical sentences how you would fix them so that they become grammatical.")
        ,
        newText("Example", "For example, if you read the sentence The cat chased mouse, you would click on the Ungrammatical button and then type a correction into the box: the mouse.")
        ,
        newText("D1", row.sentence ).bold() // assuming you list the sentences in a column named 'sentence' in gjt.csv
        ,
        newText("instructions2", "Please type G if you think the above sentence is grammatically correct, U if you think it is not grammatically correct or DK if you don't know:")
        ,
        defaultTextInput.center().lines(0).size(600,50).log().print()
        ,
        newTextInput("d1GJT", "")
        ,
        newText("CorrectionInstruction", "If you think the sentence above is ungrammatical, please fix the grammar mistake by typing the correct form in the box below:")
        ,
        newTextInput("correctionD1","")
        ,
        newText("NextPage", "Once you have answered the above questions please click Next below to go to the next question.")
        ,
        newButton("nextQ", "Next Question")
            .print()
            .wait(getTextInput("d1GJT").test.text(/.+/) )
      )
    )

    Jeremy

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.