Question T6959
Visible to All Users

Is it possible to set choices in a dropdown by some function?

created 4 years ago

Is it possible to set choices in a dropdown by some function?

Something like this

Code
{                 "type""dropdown",                 "name""Catg3",                 "title""Catg3",                 "choices""getCatgOptions()"             },

where getCatgOption return an array of string

Code
function getCatgOptions({      let catgArray: string[] = [];      categoryDataJson.forEach((catg: CategoryData) => {          catgArray.push(catg.Category);      });      return catgArray;  }  Survey.FunctionFactory.Instance.register('getCatgOptions', getCatgOptions);

Answers approved by surveyjs Support

created 4 years ago

Hello,

It's impossible to pass a function to the choices property. But you can assign the choices property at any time.

Thanks, Serge
SurveyJS Team