Have an idea?

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

Show Conditional Attribute in BYO in Alternative-Specific ACBC

Hi, I'm doing an ACBC with an Alternative-Specific design. In the BYO the conditional attributes are hidden until the respondent makes her choice for the primary attribute. Is it possible to show one of the conditional attributes on page load and only hide it after the respondent choses the other option of the primary attribute which does not belong to the respective conditional attribute?

Thank you!
asked Oct 27, 2021 by ingo Bronze (710 points)

1 Answer

0 votes
 
Best answer
Please try adding this script to your BYO:

<script>
$(document).on('ssi_ready', function(){
    // Parameters
    var attributeToShow = 3;

    // Run
    var answered;
    $('input[name="hid_list_[% QuestionName() %]"]').val().split(',').forEach(function(attribute){
        if (SSI_GetValue('[% QuestionName() %]_' + attribute)) {
            answered = true;
        }
    });
    if (!answered) {
        $('#[% QuestionName() %]_row_' + attributeToShow).show();
    }
})
</script>


Line 4 should be updated with the attribute number to be shown on page load.
answered Oct 27, 2021 by Zachary Platinum Sawtooth Software, Inc. (201,975 points)
selected Oct 28, 2021 by ingo
Hi Zachary, this is great! It even works for more than one conditional attribute. There is only one thing: Because I have an uneven number of attributes to show, the alternating colors of the following attributes are not correct. They only change after the respondent clicks the primary attribute. It would be very nice if there is a solution for this.
Thank you very much for your help!
Sorry, I've forgotten one other point: The conditional attributes should stay visible until the other option of the primary attribute is clicked. At the moment, the conditional attributes disappear as soon as you click any button.
Fixing the alternating colors is easy enough, but the other request has proven trickier.  You end up clashing with the existing JavaScript.  I was able to get the behavior to happen, but the page flashes when a response is given.  To fix that, I might have to nuke a bunch of the system JS and rebuild the BYO behavior myself.
Oh, that doesn't sound good. Perhaps I can put the primary attribute on top of the list so that (most of) the respondents first click on this. If you could provide the method for the alternating method I would be very happy.
For the alternating colors, we just need to add two more lines:

$(document).on('ssi_ready', function(){
    // Parameters
    var attributeToShow = 3;
 
    // Run
    var answered;
    $('input[name="hid_list_[% QuestionName() %]"]').val().split(',').forEach(function(attribute){
        if (SSI_GetValue('[% QuestionName() %]_' + attribute)) {
            answered = true;
        }
    });
    if (!answered) {
        $('#[% QuestionName() %]_row_' + attributeToShow).show();
    }
    $('#[% QuestionName() %]_div .byo_att_row:visible:even').removeClass('alt_color2').addClass('alt_color1');
    $('#[% QuestionName() %]_div .byo_att_row:visible:odd').removeClass('alt_color1').addClass('alt_color2');
})


Would it be acceptable to disable the non-primary attributes until the primary attribute is answered?
That wouldn't be optimal, but it might be acceptable. Perhaps the idea to sort it to the top of the list in the BYO would be sufficient. I will have to check this with our client.
...