surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.21k stars 814 forks source link

Is it possible to assign a dynamic matrix row value to the multi-select dropdown with SurveyJS using Angular? #7918

Closed chaklasiyanikunj closed 8 months ago

chaklasiyanikunj commented 8 months ago

I am using the survey JS library for creating the question. I know this is not free. I purchase 4 license and interested to use it over a long period of time.

I am trying to set dynamic matrix row values to multi-matrix columns and simple multi-select dropdowns. here is my example.

const survey = new Model(surveyJson);
survey.onComplete.add(this.alertResults);
survey.onValueChanged.add((sender: any, options: any) => {
  if (options.name == 'question1') { //Question Name
    //Column 1 is the Column name
    const myDynamicValue = options.value.map((obj: any) => obj['Column 1']).filter((value: any) => value !== undefined && value !== '');
    console.log(myDynamicValue);
    //here below question is multi matrix inside column 1 multi select drop down
    if (survey.getQuestionByName('question2')) { // Ensure question2 exists
      const question2 = survey.getQuestionByName('question2');
      console.log("question2 : ", question2);
      //how can i set myDynamicValue to particular column
    }
    //here below question is simple multi select drop down
    if (survey.getQuestionByName('question3')) {
      const question2 = survey.getQuestionByName('question3');
      console.log("question3 : ", question2);
      ////how can i set myDynamic Value to multi-select-dropdown
    }
  }
});
this.surveyModel = survey;

I have tried many ways but have not found any proper way to do this. Can anyone suggest the best way to do this?

Edited: this field is works for the set value. But, I need to know field for set options.

survey.setValue('question3', myDynamicValue); // this field is work for set value
JaneSjs commented 8 months ago

Hello @chaklasiyanikunj, In SurveyJS Form Library, you populate a multi-select matrix with a Dynamic Matrix column values using the following settings:

Let me know if you have any further questions.