The answers in the first question must be included in the second question

Hello ... I have two questions, the answers in the first question must be included or answered in the second question How to create constraints, for cases like this.

Maybe some of you can help me.Include.xlsx (11.7 KB)

Hi @Rachmat_Ramadhan
adding .=${first_question_name} in constraint column (for the second question) should work.

thank you ... what if the questions are multiple

successful if for the first and second questions are single ... what if both questions are multiple?

It should work in all question types including select_multiple. The problem is that select_multiple saves answers in the same order you select them so if you select a, b in the first question and then a, b in the second the expression will work but if you select b, a in the second question it won't work because a, b is not equal to b, a but should be in case of select_multiple.

@ln it is related to https://github.com/getodk/collect/issues/4050 what do you think about it is that a reason to fix https://github.com/getodk/collect/issues/4050 or maybe we should handle comparing select_multiple answers in javarosa to make sure cases like the one I described above are equal?

1 Like

In general I think it makes more sense to use the selected function when verifying the contents of multiple select values. It is challenging to compare two user-provided select multiples that way, though.

Are you really sure that you need to have the user select those values again, @Rachmat_Ramadhan? Could you instead do something like filter out the already-selected values the second time you show the select since they're already accounted for? Or if you're trying to confirm with the user, could you display the list of previously-selected choices and ask them to confirm?

If you really need to have them selected again and the number of possible selected choices for the first select is not very big I might do something like:

(count-selected(${other}) < 1 or selected(., selected-at(${other}, 0))) 
and (count-selected(${other}) < 2 or selected(., selected-at(${other}, 1))) 
and ...

@Grzesiek2010 Both making the choice order stable and changing the meaning of equality for multiple selects would solve the problem but I think they could have unintended consequences. Hopefully there's another form design approach that can help.

I thought about the same but it would be difficult if you had many options.

I agree about unintended consequences.

1 Like