Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How can I add conditional HTML to a question via remotecontrol2 API?

More
6 years 3 months ago #161103 by kjona
Hello,

I want to display the participants former answer with a visual feedback, if his answer was correct or not.
Manually, I can use the Expression Manager (EM) for text output with HTML tags to display the feedback nicely.

Q1: "Please select the true value" of type multiple-choice with the following
Subquestion T: "true"
Subquestion F1: "false"
Subquestion F2: "also false"

Q2: Question "Solution" displays the multiple choice form with
* the selection the participant did (lines with strlen() based check) and
* highlighting the "wrong" answers (line with NAOK based check)
with the following HTML code:

"""
You answers were:
{if(T.NAOK != "Y", '<div style="background-color:red">', '')}
{if(strlen(INSERTANS:T)>0, '<input checked="checked" type="checkbox" />', '<input type="checkbox" />')}
{if(T.NAOK != "Y", '</div>', '')}
true
<br>
{if(F1.NAOK == "Y", '<div style="background-color:red">', '')}
{if(strlen(INSERTANS:F1)>0, '<input checked="checked" type="checkbox" />', '<input type="checkbox" />')}
{if(F1.NAOK == "Y", '</div>', '')}
false
<br>
{if(F2.NAOK == "Y", '<div style="background-color:red">', '')}
{if(strlen(INSERTANS:F2)>0, '<input checked="checked" type="checkbox" />', '<input type="checkbox" />')}
{if(F2.NAOK == "Y", '</div>', '')}
also false
<br>
"""

This works great, if you paste the code into the HTML source view in the question editor. However, it does not work
when you use RemoteControl -> set_question_properties, as the HTML code is somehow "cleaned".
The above code is converted to:

"""
You answers were: {if(T.NAOK != "Y", '
<div style="background-color:#FF0000;"> </div>
', '')} {if(strlen(INSERTANS:T)>0, '', '')} {if(T.NAOK != "Y", '', '')} true<br />
{if(F1.NAOK == "Y", '
<div style="background-color:#FF0000;"> </div>
', '')} {if(strlen(INSERTANS:F1)>0, '', '')} {if(F1.NAOK == "Y", '', '')} false<br />
{if(F2.NAOK == "Y", '
<div style="background-color:#FF0000;"> </div>
', '')} {if(strlen(INSERTANS:F2)>0, '', '')} {if(F2.NAOK == "Y", '', '')} also false
"""

Can someone give me a helping hand here? (Note: I need to automatically set this text via remote control API)
Thanks,
Jonas
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose