Have an idea?

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

Display question in Gray Hidden

Hi All,

I have create a question pre-select and I want that question pre-select display in gray, it will cannot edit but still store in data when export.

Look like below:

https://drive.google.com/file/d/1MN3hVr4jn8koqyPRmXTj7QbRIplndgCT/view?usp=sharing
asked Jul 16 by Saroeun Bronze (2,715 points)

1 Answer

+1 vote
 
Best answer
The "Better Lighthouse Library" in the Community Question Library comes with easy-to-use functions for disabling radio buttons and checkboxes.  If you haven't already, you can download it from here and import it into your local question library:

https://sawtoothsoftware.com/resources/question-library/better-lighthouse-library

With the BLL included on the page, adding this script to your select question will disable all response options:

<script>
$(document).ready(function(){
    $('input[name="hid_list_[% QuestionName() %]"]').val().split(',').forEach(function(item){
        SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_' + item);
    });
})
</script>


To pre-select some responses, add lines of code like this before line 3, replacing "1" with the item to check:

SSI_SetSelect('[% QuestionName() %]_1', true);
answered Jul 16 by Zachary Platinum Sawtooth Software, Inc. (184,925 points)
selected Jul 16 by Saroeun
Thanks Zachary,

If I have 3 questions like this, I have to add BLL to all those question, right?
Not necessarily.  The code within the BLL applies to everything on the page where it appears.  If your three questions are on the same page, one instance of the BLL will handle them all.  If your three questions are on different pages, your options would be to either add the BLL to each page or to instead copy-and-paste the BLL code into a global survey settings field so that it appears on every page.

Note that the functions SSI_CustomGraphicalRadiobox and SSI_CustomGraphicalCheckbox that come baked into Lighthouse Studio are incompatible with the BLL.  If you have pages of your survey where you are using either of these functions, you either should not include the BLL on those pages or you must update your custom code to use the BLL events instead.
Thanks, working well.

Can I use BLL with Grid question? If no, how can I do?
The BLL can be placed wherever in a survey.  Do you mean whether or not we can disable the checkboxes of a grid question?
Yes, correct.
Can you show me how to disable in Grid question?
The functions for enabling and disabling radio buttons and checkboxes do support grid and free format questions, but we have to use the correct variable name for each question type.  For a select question, the first checkbox will have a name like "Q1_1".  For a grid question, we include the row and column so checkboxes end up with a name like "Q1_r2_c3".  You could try this as a simple example:

<script>
$(document).ready(function(){
    SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_r1_c1');
})
</script>


If you want to disable all checkboxes like we did with the select question, use this:

<script>
$(document).ready(function(){
    var rows = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
    var columns = $('input[name="hid_col_list_[% QuestionName() %]"]').val().split(',');
    rows.forEach(function(row){
        columns.forEach(function(column){
            SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_r' + row + '_c' + column);
        });
    });
})
</script>
I tried put this script into my footer and add BLL. It still not working.

<script>
$(document).ready(function(){
    var rows = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
    var columns = $('input[name="hid_col_list_[% QuestionName() %]"]').val().split(',');
    rows.forEach(function(row){
        columns.forEach(function(column){
            SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_r' + row + '_c' + column);
        });
    });
})
</script>
My grid question is Column Direction.
Checkbox variable names are the same for row- and column-oriented grid questions, but the same cannot be said for radio button variables.  Which are you using?
Oh, my grid question used radio button.
Radio variables in grid questions either look like "Q1_r1_2" (row-oriented) or "Q1_c1_2" (column-oriented).  Try making line 7 of that snippet look like this:

SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_c' + column + '_' + row);
Wow, perfect. Thanks so much Zachary.
Zachary, I need your help again.

With this script how can I hide question type Numeric or Open-End?

Thanks
You don't need the BLL for <input> or <textarea> elements.  You can disable those questions with code like this:

<script>
$(document).ready(function(){
    $('#[% QuestionName() %]').prop('disabled', true);
})
</script>
Thanks Zachary,

When I used, it working well but when I export data it not store data in those column. How can I get data?
My code doesn't do anything data related, it just prevents the data in the element from being altered through normal methods.  Are you looking to set a response to the field before disabling it?  You could try adding this before the disabling to edit the response:

$('#[% QuestionName() %]').val('hello world');
...