How to create a conditional string expression?
See original GitHub issueHello! 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:
- 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”.
- 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:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
@starg09 Got it! Thank you for good explanation.
Andrew
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!
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).