0

I have defined a custom question type, which name is cascadedropdown:

ComponentCollection.Instance.add({
  // A unique name; must use lowercase
  name: 'cascadedropdown', // A display name used in the Toolbox
  title: 'cascade dropdown', // A default title for questions created with this question type
  defaultQuestionTitle: 'choose the options',
  elementsJSON: [
    {
      type: 'dropdown',
      name: 'dropdown1',
      title: 'question1',
      choices: [
        {
          text:"apple",
          value:1,
        },
        {
          text:"orange",
          value:2,
        }
      ], 
    },
    {
      type: 'dropdown',
      name: 'dropdown2',
      title: 'question2',
      startWithNewLine: false,
      choices:getSecondLevelChoices(1)
    },
    {
      type: 'dropdown',
      name: 'dropdown3',
      title: 'question3',
      startWithNewLine: false,
      choices:[],
      visible: casecadeQuestionList.length > 2
    },
    {
      type: 'dropdown',
      name: 'dropdown4',
      title: '问题4',
      startWithNewLine: false,
      choices:[],
      visible: casecadeQuestionList.length > 3
    },
  ],
  inheritBaseProps: true
})

on the code above, there are at least two dropdowns in the casecadedropdown question, the second dropdown question's choices depend on the first dropdown answer. the method getSecondLevelChoices(1), the parameter 1 is the first dropdown answer's value.

How can I get the first dropdown answer's value dynamically?

The template is

<SurveyCreatorComponent :model="creator" />

1 Answer 1

0

You can solve this by defining the onValueChanged event as follows:

ComponentCollection.Instance.add({
  // A unique name; must use lowercase
  
  ... // the code above
  
  inheritBaseProps: true,
  
  onValueChanged(question,name){
    const question1 = question.contentPanel.getQuestionByName("question1");
    const question2 = question.contentPanel.getQuestionByName("question2");
    const question3 = question.contentPanel.getQuestionByName("question3");
    const question4 = question.contentPanel.getQuestionByName("question4");
    
    if(name === "question1"){
        question2.choices = getLevelChoices(levelTwoArray ,question1.value);
    }

    if(name === "question2" && question3.visible ){
        question3.choices = getLevelChoices(levelThreeArray ,question2.value);
    }

    if(name === "question3" && question4.visible ){
        question4.choices = getLevelChoices(levelFourArray ,question3.value);
    }
  }
})

Reference: expressions-and-triggers-in-composite-question-types

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.