Changelog
2024-11-04 Added LANG() function for respondent language detection
Usage example:
if LANG() == "zhs" then show Q1 # Show Q1 if respondent's language is Chinese
if LANG() == "en" then show Q2 # Show Q2 if respondent's language is English
See more in Question Display Logic
2024-06-05 Added support for random option selection
Added support for random option selection with visibility filtering and weight settings.
Uses the same syntax as random question selection, see more examples
# Q2 references Q1's answered options
if Q1A1 then show Q2A1
if Q1A2 then show Q2A2
if Q1A3 then show Q2A3
if Q1A4 then show Q2A4
if Q1A5 then show Q2A5
if Q1A6 then show Q2A6
if Q1A7 then show Q2A7
if Q1 then show Q2
# Randomize Q2 options
shuffle Q2A1~7
# Select 4 options from visible options in Q2, ensuring A2 is always selected
random show 4 from only_show Q2A1~7 weight by 1:99999:1:1:1:1:1
2024-05-24 Enhanced shuffle logic with group support
Enhanced shuffling for all question types, options, and sub-questions with support for inter-group and intra-group randomization, and fixed position options.
Description | Keyword |
---|---|
Questions grouped, shuffle between groups, fixed within groups | shuffle (Q1~3), (Q4~6) |
Questions grouped, shuffle between and within groups | shuffle (shuffle Q1~3), (shuffle Q4~6) |
Questions grouped, mixed shuffle between/within groups | shuffle (shuffle Q1~3), (Q4~6) |
Questions grouped, mixed shuffle with fixed positions (Q6 not specified, position fixed) | shuffle (shuffle Q1~3), (Q4~5) |
Questions grouped, fixed between groups, shuffle within | shuffle Q1~3 shuffle Q4~6 |
Options grouped, shuffle between groups, fixed within | shuffle (Q1A1~3), (Q1A4~6) |
Options grouped, fixed between groups, shuffle within | shuffle Q1A1~3 shuffle Q1A4~6 |
Options grouped, mixed shuffle between/within groups | shuffle (shuffle Q1A1~3), (Q1A4~6) |
Options grouped, mixed shuffle with fixed positions (Q1A6 not specified, position fixed) | shuffle (shuffle Q1A1~3), (Q1A4~5) |
Options grouped, fixed between groups, shuffle within | shuffle Q1A1~3 shuffle Q1A4~6 |
Matrix rows grouped, shuffle between groups, fixed within | shuffle (Q1S1~3), (Q1S4~6) |
Matrix rows grouped, fixed between groups, shuffle within | shuffle Q1S1~3 shuffle Q1S4~6 |
Matrix rows grouped, mixed shuffle between/within groups | shuffle (shuffle Q1S1~3), (Q1S4~6) |
Matrix rows grouped, mixed shuffle with fixed positions (Q1S6 not specified, position fixed) | shuffle (shuffle Q1S1~3), (Q1S4~5) |
Matrix rows grouped, fixed between groups, shuffle within | shuffle Q1S1~3 shuffle Q1S4~6 |
2024-05-14 Added support for matrix fill-in logic
- Use
Q1A1
to reference first column in matrix fill-in - Use
Q1S1
to reference first row in matrix fill-in - Control row/column visibility with display logic
- Use
Q1S1A1
to check if first row, first column is filled
Custom Logic
# Matrix fill-in column display logic
if Q1A1 then show Q2A1
# Matrix fill-in row display logic
if Q1A2 then show Q2S1
# Matrix fill-in completion logic
if Q2S1A1 then show Q3
2024-03-25 Added RANDBETWEEN for random number text replacement
Example
Q1. How many children in your family have participated in continuing education? [Text] Q1
Q01. Please answer the following questions about your {{Q1}} children, specifically about the {{n}}th oldest child [Descriptive Text] Q01
Custom Logic
replace "{{n}}" in Q01 title with RANDBETWEEN(1, Q1)
replace "{{Q1}}" in Q01 title with Q1
See examples in Question Content Reference.
2023-02-07 Added conditional text replacement
if Q1 >= 18 then replace "XXX" in Q01 title with "adult"
if Q1 < 18 then replace "XXX" in Q01 title with "minor"
See examples in Question Content Reference.
2022-11-28 Added date/time comparison logic
Added comparison logic for date/time questions:
if Q1 > 2020-10-24 then show Q2
Supported date/time formats:
Format | Value |
---|---|
Year | 2020 |
Year-Month | 2020-10 |
Year-Month-Day | 2020-10-24 |
Hour:Minute | 10:24 |
Year-Month-Day Hour:Minute | 2020-10-24 10:24 |
See Comparison Logic
2021-08-25 Upgraded DSL logic engine
Upgraded the DSL logic engine to support multiple expression styles and optimize logic overlap issues.
For example, to show Q2 for Q1A1, Q2-3 for Q1A2, and Q2-4 for Q1A3, you can either:
Think about "What are the conditions for showing each question?":
if Q1A1 then show Q2
if Q1A1 or Q1A2 then show Q3
if Q1A1 or Q1A2 or Q1A3 then show Q4
Or think about "What questions should be shown for each option?":
if Q1A1 then show Q2
if Q1A2 then show Q2~3
if Q1A3 then show Q2~4
Previous overlap issues have been resolved. See Display Logic Engine for details.
2021-06-09 Added support for consecutive question numbering
Now you can use Q1~4
as shorthand for Q1, Q2, Q3, Q4
in DSL statements. This works for questions, sub-questions, and options:
# Hide questions 1-4
hide Q1~4
# Hide options 1-4 in Q1
hide Q1A1~4
# Hide sub-questions 1-4 in Q1
hide Q1S1~4
3 or more sequential numbers will be automatically converted to consecutive form on page refresh. Numbers must be in order:
# Not enough consecutive numbers, won't merge
hide Q1, Q2
# Will become hide Q1~3 after refresh
hide Q1, Q2, Q3
# Won't merge due to out of order
hide Q1, Q3, Q2
2021-05-27 Added matrix sub-question random selection
Now you can use random
random statement in matrix single-choice, matrix multi-choice, and matrix scale questions to randomly select sub-questions to display.
For example, the following statement will randomly select two sub-questions to display from Q1S1, Q1S2, Q1S3, Q1S4, Q1S5.
random show 2 from Q1S1, Q1S2, Q1S3, Q1S4, Q1S5
If you want to change the probability of each sub-question appearing, you can use weight by
with it, like this:
random show 3 from Q2S1, Q2S2, Q2S3, Q2S4, Q2S5 weight by 1:5:2:3:9
If you want to randomly select from sub-questions that are not hide
, you can use only_show
with it, like this:
if Q3A1 then show Q4S1
if Q3A2 then show Q4S2
if Q3A3 then show Q4S3
if Q3A4 then show Q4S4
random show 2 from only_show Q4S1, Q4S2, Q4S3, Q4S4
See [Matrix Sub-question Random Selection](/docs/dsl/random_hide?#Matrix Sub-question Random Selection) for details.
2021-05-21 Added support for multiple content replacement in questions
Now you can use multiple replace
replace statements in the same question.
For example, using the following statements, when Q1 and Q2 are answered, Q3's title will be replaced with Q1 and Q2's answers.
if Q1 then replace "XXX" in Q3 title with Q1
if Q2 then replace "YYY" in Q3 title with Q2
2021-03-23 Added random selection logic and weighted random selection
Now you can create random selection logic in DSL. See Random Selection for details.
For example, using the following statement, you can randomly select 1 question from 4 questions.
random show 1 from Q1, Q2, Q3, Q4
If you need different probabilities for questions to be selected, you can use weighted random selection. For example, the following statement, Q1 has a probability of being selected twice as high as other questions.
random show 1 from Q1, Q2, Q3, Q4 weight by 2:1:1:1
Sometimes we want to randomly select questions that have display logic. To avoid users answering too many questions, we can limit the maximum n questions to be displayed from questions that will be displayed, thus reducing the user's answering burden and improving the recovery rate.
if Q1A1 then show Q2
if Q1A2 then show Q3
if Q1A3 then show Q4
if Q1A4 then show Q5
if Q1A5 then show Q6
if Q1A6 then show Q7
random show 2 from only_show Q2, Q3, Q4, Q5, Q6, Q7
2021-01-18 Improved shuffle logic, including shuffle for all question types, options, and sub-questions
See Shuffle for details.
2020-11-13 Added answer position comparison logic (first position in sorting question)
Added answer position comparison logic to meet the need of "showing subsequent questions after options in sorting question are ranked nth".
if index Q1A2 == 1 then show Q2 # Second option is ranked first, showing second question
See [Comparison Logic](/docs/dsl/condition?#Answer Position Comparison (xth in sorting question)) for details.
2020-11-06 Added branch to logic and text description content application
Branch to logic (branch to, convenient for writing screening questions)
In surveys, we often use screening questions to confirm that the sample we collected meets our requirements. For example, when researching the consumption habits of women aged 20 and above, if the respondent is male or younger than 20, the survey will end directly.
We can use branch to logic to implement this, like
if Q1A1 then branch from Q1 to END
See Branch to Logic for details.
Optimized the previous method of using display logic to implement screening questions
Before we could use display logic to implement similar logic, but using branch to logic would be more convenient, for example, if you have 20 questions ahead, using display logic might be like this
if Q1A1 then hide Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19
Now with branch to logic, it becomes much simpler and more readable:
if Q1A1 then branch from Q1 to END
Text Description Content Reference
Works the same way as Question Content Reference. For example: replace "xxx" in Q01 title with Q1
.
Descriptive text questions use identifiers like Q01
, Q02
because they don't count in the regular question numbering sequence.
See examples in Question Content Reference.
Support for "Other" Option Logic
Previously, conditions containing "other" options would cause DSL errors. This is now supported.
2020-10-16 Full Public Release and Documentation Update
Thanks for your support of WeSurvey's custom logic. It is now fully available to the public.
2020-09-16 Survey Editor Optimization and Preparation for Public Release
- New UI for editor
- Editor entry point
- Editor experience improvements
- Prevent leaving with unsaved changes
- "View Syntax" and "View Examples" popups
- Question and option number tags in right preview panel
- Documentation updates
- Syntax highlighting for code in documentation
- Updated existing docs to match new editor UI
- Created new quick start guide
2020-08-24 Editor UI Split View and Matrix Question Sub-question Logic
- Split view editor with adjustable size between editor and preview panels
- Support for matrix question sub-question option answered logic using syntax like
Q1S1A1
, works the same as regular option answered logic.
2020-08-17 Multiple Parameters for show/hide and UI Improvements
Multiple Parameters for show/hide
Previously, when the same condition controlled multiple questions, we had to write multiple lines:
if Q1 and Q2A1 then show Q3
if Q1 and Q2A1 then show Q4
if Q1 and Q2A1 then show Q5
if Q1 and Q2A1 then show Q6
Now you can write it in one line:
if Q1 and Q2A1 then show Q3, Q4, Q5, Q6
See examples for details.
Hover to Show Question Content
When hovering over question IDs (blue highlighted parts like Q1
, Q1A1
), shows question content. See more tips in Editor
Error Hints
Shows errors at the bottom when a line has errors.
Real-time Preview
Removed "Apply" button. Changes in the editor are now applied immediately to the preview area. Logic is applied in real-time.
2020-08-10 Syntax Highlighting, Auto-completion, and Quick Comments
- Syntax highlighting
- Highlights questions, options, and parts
- Highlights regular keywords and strings
- Auto-completion
- Auto-completes questions, options, and sub-questions with dropdown menu. See Auto-complete section
- Auto-completes keywords
- Quick comments
- Quickly comment/uncomment current line or selected lines
- Use
CMD + /
on Mac,CTRL + /
on Windows
2020-08-03 Semantic and ID-free Syntax
- Semantic syntax
- Added "if...then..." conditional statement, same as "=>"
- Added "and" logical operator, same as "&&"
- Added "or" logical operator, same as "||"
- Added "not" logical operator, same as "!"
- ID-free syntax
- Users no longer need to know question and option IDs
- Use Q1 for first question, Q1A1 for first option of first question
- Backend automatically converts between question numbers and IDs
For example, "Show Q3 when Q1 and Q2 are answered":
Old symbol-based syntax: ${q-1-abcd} && ${q-2-abcd} => show(q-3-abcd)
New semantic and ID-free syntax: if Q1 and Q2 then show Q3
You can choose your preferred style, but we recommend using the semantic syntax.
Documentation has been updated to show latest syntax. See Grammar and Examples.
!> Q1
, Q1A1
refer to the actual question numbers in the entire survey as seen in the editor, not the numbers shown to respondents. You can see these tags in the DSL editor preview area.
2020-07-27 Added len Function
See Question Answer Count Comparison for usage scenarios and examples.
2020-07-20 Added Comparison Logic
- Added comparison operators:
>
,<
,==
,>=
,<=
- Can be used with scale questions and matrix scale questions.
See Comparison Logic for usage scenarios and examples.
2020-07-13 Added show Function and Independent Save API
- Added show function as many users found using hide function with negation
!( xxx )
cumbersome. Now instead ofif !Q1 then hide Q2
, you can writeif Q1 then show Q2
. The original hide function still works. See here for notes. - Added independent save API to prevent overwrites when survey edit page is open simultaneously.
2020-07-06 Matrix Question Logic and Online Documentation Examples
- Added live preview surveys below examples in online documentation.
- Added matrix question sub-question display logic, see examples
- Added matrix question option display logic, see examples
- Added ID display for dropdown, sorting, and matrix questions in DSL editor.
2020-06-18 Option Display Logic
- Added support for option display logic, see examples
2020-06-12 Survey Copy
- Added support for copying DSL when copying surveys