Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Require responses to grid question - OE and drop down

I have a grid question that is set up with an OE for column 1, drop down (5 options) in column 2, and 5 rows that can potentially be filled in.  I need to do the following:
1. if an answer is given in the OE column (col 1), then a selection must be made in drop down column (col 2)
2. respondents can fill in up to 5 rows, but are only required to fill in 1 row completely, as long as they don't leave a row partial (see item 1)

Thanks!
asked Mar 29 by FMetzger (210 points)

1 Answer

0 votes
 
Best answer
Try setting both columns to not require a response, then give the question this custom JavaScript verification:

if (!SSI_GetValue('[% QuestionName() %]_r1_c1')) {
    strErrorMessage = 'First row must be answered.';
}

else {
    $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',').forEach(function(row){
        if (SSI_GetValue('[% QuestionName() %]_r' + row + '_c1') && !SSI_GetValue('[% QuestionName() %]_r' + row + '_c2')) {
            strErrorMessage = 'Second column must be filled if first column is answered.';
        }
    });
}
answered Mar 29 by Zachary Platinum Sawtooth Software, Inc. (171,950 points)
selected Mar 29 by FMetzger
Zachary, thanks for this.  It works well, but doesn't require an answer for col 1 if col 2 is answered.  I may not have mentioned that, but we can't have a partial row.
if (!SSI_GetValue('[% QuestionName() %]_r1_c1')) {
    strErrorMessage = 'First row must be answered.';
}

else {
    $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',').forEach(function(row){
        var c1 = SSI_GetValue('[% QuestionName() %]_r' + row + '_c1');
        var c2 = SSI_GetValue('[% QuestionName() %]_r' + row + '_c2');
        if ((c1 && !c2) || (c2 && !c1)) {
            strErrorMessage = 'Rows must be fully answered.';
        }
    });
}
Perfect!  Thanks!
...