Generate alert message based on multiple choice type question selection

I have a block style annotation interface with three multiple choice type questions. please see attached screenshot of part of the ui. I need to show an alert to the annotation UI if more than 1 checkbox is selected and prevent from saving when they hit accept. Can you please direct me how to perform that? Thank you in advance.

hi @russel,

Have you tried using validate_answer?

Here's an example in the docs for textcat where the user will get a warning unless they select 1 or 2 options (but they'll get errors if they select 0 or 3 or more):

def validate_answer(eg):
    selected = eg.get("accept", [])
    assert 1 <= len(selected) <= 3, "Select at least 1 but not more than 3 options."

So if you want to ensure they must select 1, you could use:

def validate_answer(eg):
    selected = eg.get("accept", [])
    assert len(selected) == 1, "You must select exactly 1 choice"

# just an example -- your returned dictionary may look different
return {
   "dataset": dataset,          # the dataset to save annotations to
   "view_id": "blocks",         # set the view_id to "blocks"
   "stream": stream,            # the stream of incoming examples
   "validate_answer": validate_answer, # validate answer
   "config": {
        "blocks": blocks         # add the blocks to the config
    }
}

Hope this helps!

1 Like

Thank you @ryanwesslen
I was able to make it work for multiple questions as well.
Love the prompt help and support!