Checking validity of form responses

OS (e.g. Win10): macOS Monterey
PsychoPy version (e.g. 1.84.x): 2021.2.3
**Standard Standalone? : yes

What are you trying to achieve?:

Hi everyone,

I am building an experiment and in one of the tasks I have participants fill out a form using free text. I use the responses in this form to build the stimuli for a later task so it is important that I be able to check the validity of responses before having them move on to the next routine. Since I will be running the experiment online I won’t be able to check the validity myself.

Therefore I am trying to implement a validity check using the code component. Essentially I want to check that the responses to my form items are all numerical. Only when it has been checked that all items have been completed and that all items are a number do I want them to move on to the next stage.

What did you try to make it work?:

Since buttons aren’t supported online, I made a text component called submit_form and a mouse component called submit. If the text of submit_form is clicked then participants will move on to the next step.

I have tried playing around with the opacity of the submit_form component so that the text remains invisible until participants meet the conditions: i.e. a completed form and all numerical answers, but I have been unsuccessful.

This is what my routine looks like:

I have instructions for how to fill out the form, then I have the form titled MonEval_form, the submit_form text component and corresponding mouse component. I have the submit_form opacity set to repeat every frame so that I can update the opacity.

In the end of routine tab I have the following code:

if MonEval_form.complete:
    for eachResponse in range(len(MonEval_form.items)):
        thisResponse= MonEval_form.items[eachResponse]['response']
        if isdigit(thisResponse)== True:
        elif isdigit(thisResponse)==False:

As I mentioned this did not work. So I tried a different approach:

if MonEval_form.complete:
    for eachResponse in range(len(MonEval_form.items)):
        thisResponse= MonEval_form.items[eachResponse]['response']
        if thisResponse.isnumeric()==True:
        elif thisResponse.isnumeric() == False:

if all(validResponses)==True: 

Here I start with an empty list called validResponses in which I store for each of the items whether or not it is valid input, then I check that all the list is all True and based on that I format the opacity to be 1, making the text visible. This also did not work.

I tried putting the code into the every frame tab instead of end of routine tab but that didn’t work either. Note that I don’t get error messages, the submit_form component just never appears on screen, indicating that the opacity is not updated.

If anyone has some suggestions as to how to achieve a validity check I’d be super grateful!