Input Validation
Hello,
I am trying to present a questionnare to participants. It includes different questions and rating scales. I want participants to fill each rating scale, and not to go next page until that.
I used form validation function but somehow it does not work. Could you help me please. I am sharing my script below. For clarity I used validation function only for question1 here.
def my_form_validator():
return var.question1 != u'no'
question1 = Label(text=u'Tiksinme', center=False)
question2 = Label(text=u'Korku', center=False)
question3 = Label(text=u'Öfke', center=False)
question4 = Label(text=u'Mutluluk', center=False)
question5 = Label(text=u'Şaşkınlık', center=False)
question6 = Label(text=u'Üzüntü', center=False)
question7 = Label(text=u'Nötr', center=False)
question8 = Label(text=u'arousal', center=False)
question9 = Label(text=u'valence', center=False)
ratingScale1 = RatingScale(nodes=[u'1', u'2',u'3',u'4',u'5',u'6',u'7'],var=u'question1')
ratingScale2 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question2')
ratingScale3 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question3')
ratingScale4 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question4')
ratingScale5 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question5')
ratingScale6 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question6')
ratingScale7 = RatingScale(nodes=[u'',u'',u'',u'',u'',u'',u''], var=u'question7')
ratingScale8 = RatingScale(nodes=[u'1', u'2',u'3',u'4',u'5',u'6',u'7'],var=u'question8')
ratingScale9 = RatingScale(nodes=[u'1', u'2',u'3',u'4',u'5',u'6',u'7'], var=u'question9')
image = ImageWidget(path=pool[u'3.jpg'], adjust=True, frame=False)
image1 = ImageWidget(path=pool[u'sam.jpg'], adjust=False, frame=False)
image2 = ImageWidget(path=pool[u'sam.jpg'], adjust=False, frame=False)
nextButton = Button(text=u'Next')
my_form = Form(validator=my_form_validator, rows=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], cols=[1,1,1], margins=(5,20,10,20), spacing=15)
my_form.set_widget(image, (0, 0), colspan=2, rowspan=3)
my_form.set_widget(question1, (0, 3))
my_form.set_widget(question2, (0, 4))
my_form.set_widget(question3, (0, 5))
my_form.set_widget(question4, (0, 6))
my_form.set_widget(question5, (0, 7))
my_form.set_widget(question6, (0, 8))
my_form.set_widget(question7, (0, 9))
my_form.set_widget(question8, (0, 13))
my_form.set_widget(question9, (0, 16))
my_form.set_widget(ratingScale1, (1, 3), colspan=2)
my_form.set_widget(ratingScale2, (1, 4), colspan=2)
my_form.set_widget(ratingScale3, (1, 5), colspan=2)
my_form.set_widget(ratingScale4, (1, 6), colspan=2)
my_form.set_widget(ratingScale5, (1, 7), colspan=2)
my_form.set_widget(ratingScale6, (1, 8), colspan=2)
my_form.set_widget(ratingScale7, (1, 9), colspan=2)
my_form.set_widget(image1, (1, 11), colspan=3)
my_form.set_widget(ratingScale8, (1, 13), colspan=3)
my_form.set_widget(image2, (1, 14), colspan=2)
my_form.set_widget(ratingScale9, (1, 16), colspan=3)
my_form.set_widget(nextButton, (2, 17), rowspan=2)
my_form._exec()
Comments
Hi sinem,
I am no expert, but I can tell you what I learned about the form validator.
First, you need to have as many conditions as variables: that is, in this line "return var.question1 != u'no'" you actually need to add all variables in this form.
This would look like this:
return var.question1 != u'no' and var.question2 != u'no' etc. (add as many variables as you want to check for)
Second, the condition to check if a ratingscale is "empty" or not, is this:
return var.question1 != u'None' (notice the 'None' instead of 'no')
because the default value of a ratingscale is "none".
Hope this helps!
Cheers,
Paula
Hi Paula,
Thank you very much for your help. I revised the script and it works now. I want to share in case someone may benefit from it.
def kontrol():
return var.ratingscale1 != None and var.ratingscale2 != None and var.ratingscale3 != None and var.ratingscale4 != None and var.ratingscale5 != None and var.ratingscale6 != None and var.ratingscale7 != None and var.ratingscale8 != None and var.ratingscale9 != None
question1 = Label(text='Tiksinme', center=False)
question2 = Label(text='Korku', center=False)
question3 = Label(text='Öfke', center=False)
question4 = Label(text='Mutluluk', center=False)
question5 = Label(text='Şaşkınlık', center=False)
question6 = Label(text='Üzüntü', center=False)
question7 = Label(text='Nötr', center=False)
question8 = Label(text='Arousal', center=False)
question9 = Label(text='Valence', center=False)
ratingScale1 = RatingScale(nodes=['1','2','3','4','5','6','7'],var="ratingscale1")
ratingScale2 = RatingScale(nodes=['','','','','','',''], var="ratingscale2")
ratingScale3 = RatingScale(nodes=['','','','','','',''], var="ratingscale3")
ratingScale4 = RatingScale(nodes=['','','','','','',''], var="ratingscale4")
ratingScale5 = RatingScale(nodes=['','','','','','',''], var="ratingscale5")
ratingScale6 = RatingScale(nodes=['','','','','','',''], var="ratingscale6")
ratingScale7 = RatingScale(nodes=['','','','','','',''], var="ratingscale7")
ratingScale8 = RatingScale(nodes=['1','2','3','4','5','6','7'],var="ratingscale8")
ratingScale9 = RatingScale(nodes=['1','2','3','4','5','6','7'], var="ratingscale9")
image = ImageWidget(path=pool['3.jpg'], adjust=True, frame=False)
image1 = ImageWidget(path=pool['sam.jpg'], adjust=False, frame=False)
image2 = ImageWidget(path=pool['sam.jpg'], adjust=False, frame=False)
nextButton = Button(text=u'Next')
my_form = Form(validator=kontrol, rows=19, cols=3, margins=(5,20,10,20), spacing=15)
my_form.set_widget(image, (0, 0), colspan=2, rowspan=3)
my_form.set_widget(question1, (0, 3))
my_form.set_widget(question2, (0, 4))
my_form.set_widget(question3, (0, 5))
my_form.set_widget(question4, (0, 6))
my_form.set_widget(question5, (0, 7))
my_form.set_widget(question6, (0, 8))
my_form.set_widget(question7, (0, 9))
my_form.set_widget(question8, (0, 13))
my_form.set_widget(question9, (0, 16))
my_form.set_widget(ratingScale1, (1, 3), colspan=2)
my_form.set_widget(ratingScale2, (1, 4), colspan=2)
my_form.set_widget(ratingScale3, (1, 5), colspan=2)
my_form.set_widget(ratingScale4, (1, 6), colspan=2)
my_form.set_widget(ratingScale5, (1, 7), colspan=2)
my_form.set_widget(ratingScale6, (1, 8), colspan=2)
my_form.set_widget(ratingScale7, (1, 9), colspan=2)
my_form.set_widget(image1, (1, 11), colspan=3)
my_form.set_widget(ratingScale8, (1, 13), colspan=3)
my_form.set_widget(image2, (1, 14), colspan=2)
my_form.set_widget(ratingScale9, (1, 16), colspan=3)
my_form.set_widget(nextButton, (2, 17), rowspan=2)
my_form._exec()
So glad it works! Thanks for sharing!
I want to share the working script, i deleted the first one while trying to edit :)
def kontrol():
return var.ratingscale1 != None and var.ratingscale2 != None and var.ratingscale3 != None and var.ratingscale4 != None and var.ratingscale5 != None and var.ratingscale6 != None and var.ratingscale7 != None and var.ratingscale8 != None and var.ratingscale9 != None
question1 = Label(text='Tiksinme', center=False)
question2 = Label(text='Korku', center=False)
question3 = Label(text='Öfke', center=False)
question4 = Label(text='Mutluluk', center=False)
question5 = Label(text='Şaşkınlık', center=False)
question6 = Label(text='Üzüntü', center=False)
question7 = Label(text='Nötr', center=False)
question8 = Label(text='Arousal', center=False)
question9 = Label(text='Valence', center=False)
ratingScale1 = RatingScale(nodes=['1','2','3','4','5','6','7'],var="ratingscale1")
ratingScale2 = RatingScale(nodes=['','','','','','',''], var="ratingscale2")
ratingScale3 = RatingScale(nodes=['','','','','','',''], var="ratingscale3")
ratingScale4 = RatingScale(nodes=['','','','','','',''], var="ratingscale4")
ratingScale5 = RatingScale(nodes=['','','','','','',''], var="ratingscale5")
ratingScale6 = RatingScale(nodes=['','','','','','',''], var="ratingscale6")
ratingScale7 = RatingScale(nodes=['','','','','','',''], var="ratingscale7")
ratingScale8 = RatingScale(nodes=['1','2','3','4','5','6','7'],var="ratingscale8")
ratingScale9 = RatingScale(nodes=['1','2','3','4','5','6','7'], var="ratingscale9")
image = ImageWidget(path=pool['3.jpg'], adjust=True, frame=False)
image1 = ImageWidget(path=pool['sam.jpg'], adjust=False, frame=False)
image2 = ImageWidget(path=pool['sam.jpg'], adjust=False, frame=False)
nextButton = Button(text=u'Next')
my_form = Form(validator=kontrol, rows=19, cols=3, margins=(5,20,10,20), spacing=15)
my_form.set_widget(image, (0, 0), colspan=2, rowspan=3)
my_form.set_widget(question1, (0, 3))
my_form.set_widget(question2, (0, 4))
my_form.set_widget(question3, (0, 5))
my_form.set_widget(question4, (0, 6))
my_form.set_widget(question5, (0, 7))
my_form.set_widget(question6, (0, 8))
my_form.set_widget(question7, (0, 9))
my_form.set_widget(question8, (0, 13))
my_form.set_widget(question9, (0, 16))
my_form.set_widget(ratingScale1, (1, 3), colspan=2)
my_form.set_widget(ratingScale2, (1, 4), colspan=2)
my_form.set_widget(ratingScale3, (1, 5), colspan=2)
my_form.set_widget(ratingScale4, (1, 6), colspan=2)
my_form.set_widget(ratingScale5, (1, 7), colspan=2)
my_form.set_widget(ratingScale6, (1, 8), colspan=2)
my_form.set_widget(ratingScale7, (1, 9), colspan=2)
my_form.set_widget(image1, (1, 11), colspan=3)
my_form.set_widget(ratingScale8, (1, 13), colspan=3)
my_form.set_widget(image2, (1, 14), colspan=2)
my_form.set_widget(ratingScale9, (1, 16), colspan=3)
my_form.set_widget(nextButton, (2, 17), rowspan=2)
my_form._exec()