question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Populate coded values via code only (ignoring text)

See original GitHub issue

A proposal / question

It would be great if the logic of the surveys would be able to operate on coded choices only (if coded) and ignore the text labels.

What is the current behavior?

I’m not sure (yet how the filtering & conditions work), but for populating/ setting data, it only works if both code and text match.

A simple example of what I mean.
let’s say I have a question like :

{
    type: "radiogroup",
    name: "car",
    title: "What car are you driving?",
    isRequired: true,
    choices: [
        {'code':1, "text":"Ford"},
        {'code':2, "text":"BMW"},
        {'code':3, "text":"Ziguli"}
    ]
}

right now, in order to set the value, one would need to have it like:

survey.data = {car: {code:1,text:'Ford'}};

What is the expected behavior?

I think it would be logical if only this would be enough:

survey.data = {car:1};

If the choices are coded, using codes will resolve numerous issues like

  • simplicity
  • translation issues (having texts in various languages needs separate attention & a layer of management)
  • Changeability. Mostly you need to change the label / text only. What if you change the form coded text and you have some values stored with a different text?
  • less data to store. Storing {car:1} takes much less space than {car: {code:1,text:'Ford'}} Imagine if you would have some code in the text labels (eg html).

Thank you for a cool library!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewtelnovcommented, May 6, 2020

@TonisOrmisson You should use value in expressions and it means that {haveKids}=5 works perfectly. choices : [1, 2] is the same as choices : [{value: 1}, {value: 2}] and text is optional and surveyjs uses it for displaying in UI only. Adding text as: choices : [{value: 1, text: "first year"}, {value: 2, text: "second year"}] doesn’t change the way it works in expression.

Thank you, Andrew

0reactions
TonisOrmissoncommented, May 6, 2020

@andrewtelnov thank you!

You are completely right. And seems the setting also works perfectly. It seems that my mistake was wrongly using code instead of value. 🤦‍♂️

excellent work guys

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make html ignore code that is part of text?
Short Answer. Encode your code using an online HTML Encoder and then put it inside pre <pre> <%--your encoded code goes here--%> </pre>....
Read more >
Keeping leading zeros and large numbers
Excel automatically removes leading zeros, and converts large numbers to scientific notation, like 1.23E+15, in order to allow formulas and math operations to ......
Read more >
Excel conditional formatting formulas based on another cell
This method works for any data types: numbers, text values and dates. Select the column where you want to highlight duplicates, without the ......
Read more >
Excel Data Validation Tips and Troubleshooting
Why does this happen, and how can you prevent it? Get the sample file in the download section. drop down list blank. Cause:...
Read more >
Text formatting tags—ArcGIS Pro | Documentation
The Annotation syntax applies to text in the page layout, the values of fields used to label ... Use the equivalent character codes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found