Have an idea?

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

Error Message for first column of grid

I have a question (Q5) that is a row-oriented radio-button grid with 6 columns and 15 rows. I want to allow only one answer in the first column, so only one of the 15 rows can have a selection in that column. There are no restrictions on how many times the other columns can be used to answer across the rows.
I want to show an error message when people select the first column for more than one row saying" Please review your answers. Only one brand can be selected as your primary one." and let them continue only when one is selected.
How would the javascript code look like to do this?
asked Oct 30, 2021 by rinsights Bronze (890 points)

1 Answer

+1 vote
Try giving the grid question this custom JavaScript verification:

var foundColumn1 = false;
$('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',').forEach(function(row){
    if (SSI_GetValue('[% QuestionName() %]_r' + row) == 1) {
        if (foundColumn1) {
            strErrorMessage = 'Please review your answers.';
        }
        foundColumn1 = true;
    }
});
answered Nov 1, 2021 by Zachary Platinum Sawtooth Software, Inc. (212,550 points)
Thank you, Zach! How would this code change if we were to apply this logic to another column in the grid?
Replace the number on line 3.
Thank you!
I need to show this error message in English and Spanish based on a language question called Sp. How would the code look like for that to work?
Something like this perhaps?

switch ([% LanguageVar %]) {
    case 1:
        strErrorMessage = 'one message';
        break;
    case 2:
        strErrorMessage = 'another message';
        break;
}
As long as it shows a different message based on the language variable, which is called Sp. Where do you add this last piece of code to the previous one? I'm not sure how to combine them. I tried a couple of options that didn't work.
In place of line 5.
Thank you, Zach.
...