Have an idea?

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

ACBC: How to check presence of a certain level of an attribute

Hi,

I want to change the response choice to the screener section of ACBC based on the presence of a certain level of an attribute.

In presence of level 1 in 2nd attribute, we do nothing, we leave the response choices as the default choices ('A possibility' and 'Won't work for me').

I want to change the response choices change if it doesn't present.

Please let me know how to do this.
asked Aug 19, 2016 by Abdul Bronze (2,630 points)
What do you want to change about the response options when this level is not present?  Do you just want to change how the buttons are labeled?
Yes Zachary, just need to change the label.
I have added this code in 'Concept Acceptance Label' but don't know logic/syntax to add. Please see below.
[%
begin unverified perl
if()
{
return "A possibility";
}
else
{
return "NEED TO GET TEXT FROM CLIENT";
}
end unverified
%]

1 Answer

+2 votes
 
Best answer
Using unverified Perl in those Screening fields is a clever idea, but I'm not sure that we have the necessary Perl functions to make this work.  As an alternative, we can do this client-side with some JavaScript.

To start, add this to the first level of the second attribute:

<input type="hidden" class="att2lvl1">


(You may want to set an internal label to keep the code out of analysis.)

Now, put this code in the footer of the Screening questions:

<script>
var numberOfAttributes = 4;
var numberOfConcepts = 4;
var possibilityAlt = 'A possibility 2';
var wontWorkAlt = 'Wont work for me 2';

for (var concept = 1; concept <= numberOfConcepts; concept++) {
    if ($('.acbc_screener > .question_body > table > tbody > tr:nth-child(2) > td:nth-child(' + (concept + 1) + ') .att2lvl1').length == 0) {
        $('.acbc_screener > .question_body > table > tbody > tr:nth-child(' + (numberOfAttributes + 1) + ') > td:nth-child(' + (concept + 1) + ') tbody > tr:nth-child(1) label')
            .text(possibilityAlt);
        $('.acbc_screener > .question_body > table > tbody > tr:nth-child(' + (numberOfAttributes + 1) + ') > td:nth-child(' + (concept + 1) + ') tbody > tr:nth-child(2) label')
            .text(wontWorkAlt);
    }
}
</script>


Line 2 should be updated with the number of attributes in the ACBC exercise.  Line 3 should be updated with the number of concepts in each Screening question.  Lines 4 and 5 can be updated with the text from the client.
answered Aug 19, 2016 by Zachary Platinum Sawtooth Software, Inc. (147,925 points)
selected Aug 22, 2016 by Abdul
Thank you so much Zachary. Much appreciated.
...