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.

How to create a conditional string expression?

See original GitHub issue

Hello! Been trying the library, and porting over a reporting survey from an alternative system. There’s two main things I did on said previous system, and that I ended up doing here in a similar way:

  1. I ask them (optionally) for a contact username. While testing the available features on surveyjs, I wanted to place a regex restriction depending on what option they chose: If they chose Discord, they’d have to be “username#9999”, and if they chose reddit they’d use “/u/username”.
  2. I make a good amount of logic jumps, giving different questions and options depending on previously selected options. I think this could be optimized, but right now it doesn’t really change the issue that much.

Which brings my current question: I’d like to include a confirmation page before the user completes the submission, something like this. But so far I can’t seem to find a way to process the answers inside the survey itself. I can get specific answers to display, but what I’d be looking for is something combining many of them, and using some only if a certain condition is met… What I wonder is, is there some way to, as examples:

  • Print “{username_discord}” here only if {contact_info_choice} = “discord”
    • Alternative to this: Set {username} (“Expression (read-only)” block) depending on the value of {contact_info_choice}. Then just print {username}.
  • Print {quest_type} + ( ("[" + <name conditional> + "]") if {quest_type} = "MSS") + ( {ch_number} if ({quest_type} != "D" && {quest_type} != "MSS") ) + <more similar conditions>

Here’s a gist of my current survey json

I’ve been looking around the site and customer portal for hours, solved many other questions I had but just can’t find a solution to this. I’d really appreciate if you could help me, thank you for reading.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
andrewtelnovcommented, Dec 19, 2019

@starg09 Got it! Thank you for good explanation.

Andrew

0reactions
starg09commented, Dec 19, 2019

Oh! Wasn’t aware of those custom functions, not sure how I missed those… That works perfectly for what I was looking for, haha!

Thanks for the quick reply!

By the way, just curious, from what platform are you migrating from? and what is the reason? We have plans, not immediately so, to work on imports from popular survey platforms. Do you feel we missed something?

Well, I’ve been trying some different open source alternatives as to replace an old Google Form for a “game farming report” spreadsheet. For the last couple months I’d been trying Tripetto, which is pretty nice but still missing a couple small features. While trying to understand their custom blocks SDK as to improve the form in some ways I stumbled upon survey.js and decided to give it a shot as well, and I feel it might work pretty well for some stuff I wasn’t able to do over there 😃

Being able to migrate from their system would certainly be a nice feature, since it’s also built as a structure and not with a specific display format in mind (and can be self-hosted, so a form definition could be passed manually without much trouble).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex Tutorial - If-Then-Else Conditionals
A special construct (?ifthen|else) allows you to create conditional regular expressions. If the if part evaluates to true, then the regex engine will ......
Read more >
Conditional expression - Cornell CS
The conditional expression · Be careful. The conditional operators · Here's an example that creates a string that indicates which is the larger...
Read more >
Conditional statements
Review of IO and strings. ... The conditional operator lets us choose between two expressions to evaluate, depending on a Boolean condition.
Read more >
the ternary conditional operator - Microsoft Learn
The conditional operator ?: , also known as the ternary conditional operator, evaluates a Boolean expression and returns the result of one ...
Read more >
Conditional (ternary) operator - JavaScript - MDN Web Docs
Besides false , possible falsy expressions are: null , NaN , 0 , the empty string ( "" ), and undefined . If...
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