Skip to content

Allow variables to have choices #9799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SamMousa opened this issue Apr 25, 2025 · 1 comment
Open

Allow variables to have choices #9799

SamMousa opened this issue Apr 25, 2025 · 1 comment
Assignees
Labels

Comments

@SamMousa
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Imagine I add a variable to a survey. The possible values for this variable are A, B, C.

survey.setVariable('Test', 'A')

In the creator I will be able to add routing based on this variable:

Image

Describe the solution you'd like
It'd be great if there was some way to let the survey engine / creator know that the possible values are just A, B and C.
This will allow for a way cleaner UX when setting up conditions.

Describe alternatives you've considered
The only alternative I have found is to create constructs like hidden questions that are used to define a "schema" ie choices, but is are never shown to the user.

Additional context
Variables are one thing where this is relevant, but calculated values suffer the same.

What we'd need in theory, not sure how to do it in practice, is something that:

  • Behaves like a single or multiple choice question when it comes to configuring choices
  • Is never shown to the user
  • Has a "realtime" value similar to calculated values.
@andrewtelnov andrewtelnov added enhancement user issue An issue or bug reported by users labels Apr 25, 2025
@andrewtelnov andrewtelnov added question and removed enhancement user issue An issue or bug reported by users labels Apr 28, 2025
@andrewtelnov
Copy link
Member

@SamMousa Here is the code and the example.

    const varName = "test";
    creator.survey.setVariable(varName, 'A')
    creator.onConditionGetQuestionList.add((sender, options) => {
      const index = options.variables.indexOf(varName);
      if(index > -1) {
        options.variables.splice(index, 1);
        const q = new Survey.QuestionDropdownModel(varName);
        q.choices = ["A", "B", "C"];
        options.list.push({
          name: varName,
          text: "Please select option for Test",
          question: q
        })
      }
    });

Thank you,
Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants