Displaying multiple error messages

279 views
Skip to first unread message

Max Spohn

unread,
Jul 9, 2021, 1:56:46 PM7/9/21
to oTree help & discussion
Hi all, 

I am looking for a way to display multiple error messages at the same time. In the following example both conditional statements could be true, in which case I would like the error message after the failed validation to display:

Errors
  • Message 1
  • Message 2

def error_message(self, values):
    print ('values is', values)
    if values["var1"] == 1 and values["var2"] != 0: 
        return "Message 1"
    if values["var1"] == 1 and values["var3"] == None:
        return "Message 2"   

Can this be done? Thanks a lot for your help.

Best,
Max

Chris Crabbe

unread,
Jul 9, 2021, 1:59:08 PM7/9/21
to Max Spohn, oTree help & discussion
Hi Max -

If you make a third conditional before those two with both conditions (and both messages) it would trigger first and only when all conditions are filled:

if values["var1"] == 1 and values["var2"] != 0 and values["var1"] == 1 and values["var3"] == None:
    return 'Message 1 and Message 2'

Thanks,
--Chris

--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/14f22737-fb51-42f7-a428-f5237b826252n%40googlegroups.com.

Max Spohn

unread,
Jul 12, 2021, 6:53:53 AM7/12/21
to oTree help & discussion
Thanks. Is there a more efficient solution though? The code above was only an example, in my case I would actually need fourteen conditions per page, so I was hoping there was a better solution? 

Chris @ oTree

unread,
Jul 12, 2021, 4:59:42 PM7/12/21
to oTree help & discussion
Reply all
Reply to author
Forward
0 new messages