Hi all,
I want to make sure the user selects at least one option of a checkbox question.
The trick is that the checkbox is inside a for loop.
The simple scenario is if we ought to ask the user's favourite vacation spot (single answer) and then ask in which seasons she likes to go there (checkbox).
However, to my understanding, a checkbox-type question allows blank answer (i.e.: no alternative selected).
Thus, if I wanted to enforce the selection of at least one alternative, I'd check the answer size and use label and goto to send the user back to the question with a message. The user cannot proceed until she selects at least one alternative.
Here's a sample code.
>>selection_warning = 0
*header: Single Selection
*question: What's your favourite vacation spot?
*save: vacation_spot
Beach
Mountain
City
*label: season_selection
*if: selection_warning = 1
*html
<p style="color:red; font-style:italic;">Please, select a season.</p>
*question: In which seasons do you like to go to the *{vacation_spot}*?
*save: seasons
*type: checkbox
Summer
Spring
Winter
Fall
*if: seasons.size=0
>>selection_warning = 1
*goto: season_selection
In *{seasons}* you like going to the *{vacation_spot}*.
>>selection_warning = 0
Now, let's say that I want to allow multiple selections for the favourite vacation spots.
Then, I'd like to loop over each selected vacation spot to know the preferred seasons for each spot.
However, the for loop doesn't allow me to use a *goto (understandably).
Here's an example:
>>selection_warning = 0
*header: Multiple Selection - For Loop
*question: Which vacation spots do you like?
*save: vacation_spots
*type: checkbox
Beach
Mountain
City
>>spot_seasons = {}
*for: spot in vacation_spots
--*label: season_selection
*if: selection_warning=1
*html
<p style="color:red; font-style:italic;">Please, select a season.</p>
*question: In which seasons do you like to go to the *{spot}*?
*save: seasons
*type: checkbox
Summer
Spring
Winter
Fall
*if: seasons.size=0
>>selection_warning = 1
--*goto: season_selection
-- How can I make sure the user selects at least one checkbox?
>>spot_seasons[spot] = seasons
*for: spot,season in seasons
In *{season}* you like going to the {spot}.
Then, the question is: How to enforce that each checkbox question inside the loop has at least one selection?
Any ideas or thoughts would be greatly appreciated!
Thanks in advance!