Have an idea?

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

Implementing Constructed list in free format

Hi,

I have created a grid question in Free Format due to the lay out of this question.
My grid in answered by columns and the columns need to be shown/hidden depending on the answers at a previous question. I have therefore created a constructed list to do so, but not sure what is the syntax to add in the Free Format question to use the constructed list created.
Anyone has any idea how to do this?
asked Jul 18, 2016 by Jack

3 Answers

+1 vote
I would start by making a column for each item in the parent list, then hide some of them using JavaScript / jQuery and Sawtooth Script.  There are a number of Sawtooth Script functions that could be of use -- I'd recommend "ListValuesArray."  You can hide all columns that aren't listed in that array.
answered Jul 18, 2016 by Zachary Platinum Sawtooth Software, Inc. (84,025 points)
I'm confused....
Not sure I understand what are the steps here...
here is the script I have made:
<table border="5" cellpadding="20" cellspacing="50" width="150">
<tr>
     <th>Country</th> //this is not to hide
    <th>Financial service</th> //this is not to hide
    <th>Checking account</th>
    <th>Foreign currency current/ savings/ demand/ deposit account</th>
    <th>Credit card</th>
    <th>Savings account – instant access</th>
    <th>Savings account – CD (Certificate of Deposit)</th>
    </tr>
   
    <td rowspan="9"><b><font size="5">Canada</font></b></td>
   
    <tr class="clickable">
        <td>
            Bank of Montreal
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>   
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 1)%]
        </td>
    </tr>
        <tr class="clickable">
        <td>
            Bank of Nova Scotia
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>   
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
        <td class="input_cell">
            [%CheckSelect(S6b_A, 2)%]
        </td>
    </tr>
Heads up, you seem to have a "td" not inside a "tr" near the beginning of the code.

Here's a quick start at the JS:

<script>
$(document).ready(function(){
    var colsToShow = [% ListValuesArray(ConstList) %];
    for (var c = 1; c <= 7; c++) {
        if ($.inArray(c, colsToShow) == -1) {
            $('#FreeFormatQ .question_body table > tr > :nth-child(' + (c + 1) + ')').hide();
        }
    }
})
</script>


"FreeFormatQ" should be replaced with the free format's name.  "ConstList" should be replaced with the constructed list's name.
Thank a lot Zachary, I'll give it a try! :)
0 votes
Hi Jack,

Can you let us know the layout of grid you are trying to build using free format. We can try to make this using standard grid question itself using jquery functions. This will enable you to use standard verified perl functions. As an alternative, you can use solution provided by Zach
answered Jul 18, 2016 by Saurabh Aggarwal Gold (29,275 points)
it is basically a grid question layout but with an extra column for the country which is merged for the number of brands in this country.
Something like:

Country        Brand              Col1         Col2
                         Brand1
Country1      Brand2
                         Brand3
                         Brand1
Country2      Brand2
                         Brand3
0 votes
HI
I replied same type of question in a few years back here. go to the link below. I have used grid question instead of free format.

https://sawtoothsoftware.com/forum/5501/depending-drop-down-lists


Let me know if you need more help here.
answered Jul 18, 2016 by Rajesh Rana Gold (23,430 points)
Yes I think this is the fastest solution for now.
 I will try to play around when I have more time.
...