Welcome to the LimeSurvey Community Forum

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

Pre-populating answers with custom token attributes

More
9 years 5 months ago #113296 by jpperrein
Hi,

Ok, many thanks, indeed, I can choose a default value for text purpose. That works fine.
But what if I want to set the default value to an {TOKEN:ATTRIBUTE_1} to a List (radio) question ? - I do not have any place to add my variable, like the text one.

Any clues ?

Many thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 5 months ago #113299 by tpartner
To set defaults for radio questions you can use the Expression Manager Assignment operator in a following equation type question - manual.limesurvey.org/Expression_Manager..._Assignment_Operator

Be sure to make it conditional on the radio being unanswered. Something like:
Code:
{qRADIO = if(qRADIO == "", TOKEN:ATTRIBUTE_1, qRADIO)}


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 5 months ago #113303 by jpperrein
Re,

Ok, the condition is a good thing, thanks.
But I did test it and it does fill the question text but do not change anything on the answer :

What I have done : (ATTRIBUTE_1 = CAT1)

CODE : categorie
QUESTION: Hello, this is my question ... ?
{Categorie = if(Categorie == "", TOKEN:ATTRIBUTE_1, Categorie)}
HELP :nohelp

And the result is
TEXT of QUESTION : Hello, this is my question ... ?
CAT1

O Catégorie 1 (do have the code CAT1)
O Catégorie 2 (do have the code CAT2)
O Catégorie 3 (do have the code CAT3)

So it does "write" CAT1, but on the text of the question, not changing the value of the choice itself.

Hard to explain, sorry :side: .Do you see the issue ?

Many thanks for your help.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 5 months ago - 9 years 5 months ago #113304 by tpartner
You need to put the expression into a hidden equation type question that follows categorie.

Question type - single-choice-radio
Question code - categorie
Question text - Hello, this is my question ... ?
Answers - Catégorie 1 (code CAT1), Catégorie 2 (code CAT2), Catégorie 3 (code CAT3)

Question type - equation
Question code - catControl
"Always hide this question" - yes
Question text - {categorie = if(categorie == "", TOKEN:ATTRIBUTE_1, categorie)}

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 5 months ago by tpartner.
The topic has been locked.
More
6 years 1 month ago #163353 by abudzarr
I have got a similar problem, and I have tried to follow the recommendation suggested here.

Linked below is the script I have entered

snag.gy/hiI2HD.jpg

I would expect that the short-text answer would be auto-filled with token attributes

but I failed to get the expected result. snag.gy/5anUIN.jpg

Will appreciate if someone can point out where did I go wrong.

Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #163359 by tpartner
The script should be:

Code:
<script>
   $(document).ready(function() 
   {
      $("#question{QID} input.text").val('{TOKEN:EMAIL}');
   });
</script>

You could also do it by placing a hidden (via CSS class) equation question directly after R01 with this equation:

Code:
{R01 = (is_empty(R01), TOKEN:EMAIL, R01)}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 1 month ago by tpartner.
The following user(s) said Thank You: jpperrein, abudzarr
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose