- Posts: 17
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Programmatically answer and style questions based on previous answer
- Haris.Pap
- Topic Author
- Offline
- New Member
Own server or LimeSurvey hosting: LS Community on own server
Survey theme/template: Vanilla extension
===================
Hi everyone
I am trying to auto-answer questions based on previous answers, using a Group by Group survey format. The target questions are scattered in different Question-groups within the survey. So far so good – this can be well achieved using an equation question .
However, I also need to style the target questions so that it’s clear that they have been auto-answered (eg. having a green background and a hint-text).
For this purpose, I tried using the update_response API-function, followed by set_question_property for the styling (not there yet).
My problems with this approach are:
- Auto-answered questions appear empty, although they are dynamically set successfully (as seen in the responses)
- Auto-answers are overwritten when the survey is saved or submitted (I guess because the fields remain empty)
> Is there a way to display those auto-answers when navigating to the related Question-groups?
> If yes, is there a better way to get the target answers’ names than using list_questions (API) and compose their SGQ code?
Thanks for your help
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10634
- Thank you received: 3698
If you are using ExpressionScript to set the question, you should also be able to use ExpressionScript to define a CSS class for the question.However, I also need to style the target questions so that it’s clear that they have been auto-answered (eg. having a green background and a hint-text).
- manual.limesurvey.org/Question_type_-_Li...lass_.28css_class.29
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- Haris.Pap
- Topic Author
- Offline
- New Member
- Posts: 17
- Thank you received: 0
Do you mean that it's possible to set a css class of another question via the logic field of an equation question?
- I checked Expression Manager's " Access to variables ", but there is nothing mentioned
- I tried this code within an equation question too, but it doesn't work: {Q02.css_class= "autoAnswered"}
> Is there a way to display those auto-answers when navigating to the related Question-groups?
> If yes, is there a better way to get the target answers’ names than using list_questions (API) and compose their SGQ code?
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
- Posts: 12790
- Thank you received: 3940
I think, Tony wanted to say:Do you mean that it's possible to set a css class of another question via the logic field of an equation question?
"In the field "css classes" of this question enter something like {if(yourCondition,"autoAnsweredClass","")}
And I do not understad your further questions.
Regarding the second:
What do you "compose"? In "Access to variables" there is a property ".sgqa"
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- Haris.Pap
- Topic Author
- Offline
- New Member
- Posts: 17
- Thank you received: 0
Thanks for clarifying this, it worked well. I am attaching an example survey, in case anyone needs to have a look.I think, Tony wanted to say:
"In the field "css classes" of this question enter something like {if(yourCondition,"autoAnsweredClass","")}
It's good to mention though, that this won't work dynamically on the same page - It works well for target questions found on upcoming pages.
Let's take it step-by-step:Regarding the second:
What do you "compose"? In "Access to variables" there is a property ".sgqa"
> (Using the update_response API-function) Auto-answered questions appear empty, although they are dynamically set successfully (as seen in the responses)
Trying to re-phrase the question below:
Why would an answer field appear empty, if an answer is set to it programmatically in a previous question group (using the update_response API-function)?
Thx again
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10634
- Thank you received: 3698
Maybe it's related to the session.Why would an answer field appear empty, if an answer is set to it programmatically in a previous question group (using the update_response API-function)?
But, why use the API to set the questions? Can't you do it with ExpressionScript in the previous page?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
- Posts: 12790
- Thank you received: 3940
You may use your two css classes
Like: {if(Q00 == 'test',"show-alert","no-alert")}
Seeing your "alert-warning" I suppose you want to show a bootstrap alert.
First you have to insert the alert. Here with a "close" option
<div class="conditional-text alert alert-warning alert-dismissible" role="alert"> <button aria-label="Close" class="close" data-dismiss="alert" type="button"> <span aria-hidden="true">×</span> </button> This question was auto-answered </div>
And some rough css:
<style type="text/css"> /* 1. To show the alert and change background and color of the answer */ .show-alert .form-control { background-color:yellow; color: red; } /* 2. To hide the alert */ .no-alert .alert { display:none; } </style>
Either this
or this
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- tammo
- Offline
- Official LimeSurvey Partner
- Posts: 964
- Thank you received: 217
www.respondage.nl/scoring_an_array/
You can download the survey and see how it is done.
Tammo
Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Please Log in to join the conversation.
- Haris.Pap
- Topic Author
- Offline
- New Member
- Posts: 17
- Thank you received: 0
Indeed, an Equation question is great for auto-answering questions. There are some peculiarities and limitations though, which do not seem documented yet ... ð Suggestion: Expand the related Manual page with the attached guide and / or link both ways to the related EM section . Any improvements are very welcome.
I am really not informed here, how this can be related to the session (do you mean a caching issue?).
Maybe it's related to the session.Why would an answer field appear empty, if an answer is set to it programmatically in a previous question group (using the update_response API-function)?
But, why use the API to set the questions? Can't you do it with ExpressionScript in the previous page?
Shouldn't each page show the related stored answers when loaded?
There are still two reasons, why I would still use the API to set the answers:
- An Equation question will not (yet?) work with OfflineSurveys (related forum discussion | workaround1 on page2 | workaround2 )
- An Equation question cannot set answers dynamically on the same page of the triggering question, which can easily be handled by javascript (see for example workaround1 above).
Please Log in to join the conversation.