Asking multiple questions in one task (different input types)

Hi! That's an interesting question :slightly_smiling_face:

Since you can only have one instance of an interface per task (because the data would overwise get messy and have conflicts), I would probably do something like this:

blocks = [
    {"view_id": "choice"},
    {"view_id": "html", "html_template": HTML_TEMPLATE, "javascript": JAVASCRIPT},
    {"view_id": "text_input"}
]

For the choice block, your task could specify a list of "options" that's displayed. For the html block, you could have a simple HTML template with a checkbox and a small JavaScript script that listens to the checked event of the box and updates the task with whether it's checked. And the text_input will create a text box and add whatever the user types as the key "user_info" (or a custom field_id).

The HTML and JavaScript could look like this – when Prodigy is mounted, you listen to any change of the checkbox and then add a field "checked" to the task indicating whether it was checked (or whatever else you need):

<input type="checkbox" id="checkbox" />
document.addEventListener('prodigymount', () => {
    const checkbox = document.querySelector('#checkbox')
    checkbox.addEventListener('change', event => {
        window.prodigy.update({ checked: event.target.checked })
    })
})

In theory, that's possible with the same approach shown above. You can define your HTML elements, access them in JavaScript, listen to changes (or other things) and call window.prodigy.update to update the current annotation task.

At the moment, that's a bit tricky, but Prodigy v1.10 should have you covered :smiley: You'll then be able to define a validate_answer callback in your custom recipe that's called on every answer the annotator submits in the UI. So you can pretty much assert anything and/or raise errors that are then shown to the annotator in an alert. And the task can only be answered if validation passes (or it can be skipped, of course).

Here's an example for how you could validate a mandatory choice selection:

def validate_answer(eg):
    selected = eg.get("accept", [])
    if not selected:
        raise ValueError("Please select at least one option!")