# Asking multiple questions in one task (different input types)

**URL:** <https://support.prodi.gy/t/asking-multiple-questions-in-one-task-different-input-types/2990>\
**Category:** Uncategorized\
**Tags:** solved, front-end, usage, custom\
**Created:** [June 5, 2020, 4:05pm UTC](https://support.prodi.gy/t/asking-multiple-questions-in-one-task-different-input-types/2990 "2020-06-05T16:05:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [June 5, 2020, 9:26pm UTC](https://support.prodi.gy/t/asking-multiple-questions-in-one-task-different-input-types/2990/2 "2020-06-05T21:26:10Z")

</div>

Hi! That's an interesting question 🙂

> [@fhamborg](#):
>
> use the prodigy's blocks UI element and use various elements. How would the corresponding "blocks" definition need to look like?

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:

```python
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):

```html
<input type="checkbox" id="checkbox" />

```

```javascript
document.addEventListener('prodigymount', () => {
    const checkbox = document.querySelector('#checkbox')
    checkbox.addEventListener('change', event => {
        window.prodigy.update({ checked: event.target.checked })
    })
})

```

> [@fhamborg](#):
>
> Also, how can I access what users type into a form element, e.g., a textarea?

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.

> [@fhamborg](#):
>
> If there is a way regarding checking mandatory and optional - that would be great, but we can also deal with this by using proper labeling instructions.

At the moment, that's a bit tricky, but Prodigy v1.10 should have you covered 😃 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:

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

```

---

_[View the full topic](https://support.prodi.gy/t/asking-multiple-questions-in-one-task-different-input-types/2990)._
