Hi
im creating custom widgets dropdown list, I want to create propety which will enable to fetch data from server store it as itemvalue.
Then in properties i can select/deselect from those list
example
widgets loads fetch county list
in settings i go to country list i see itemvalue answers and select deselect values i want
rest will be handled in after render by custom render
i used this example
JavaScript```javascript
Survey.Serializer.addProperty("survey",
{ name: "country", category: "general",
choices: function(obj, choicesCallback) {
//We are going to use choicesCallback here
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://restcountries.eu/rest/v2/all");
xhr.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded"
);
//on load event set results into array of ItemValue and tell the Survey Creator that choices are loaded.
xhr.onload = function() {
if (xhr.status === 200) {
var serverRes = JSON.parse(xhr.response);
var res = [];
//We will use ItemValue array here, since we want to have value different from display text
//If your value equals to display text, then you may simply return the array of strings.
res.push({ value: null });
for (var i = 0; i < serverRes.length; i++) {
var item = serverRes[i];
res.push({ value: item.alpha2Code, text: item.name });
}
//return the result into Survey Creator property editor
choicesCallback(res);
}
};
xhr.send();
}
});
but it return simply dropdown, i cannot select/unselect values like in img attached
regard K.K
Code
Hello,
Did you try to use choicesByUrl property of
QuestionSelectBase
class to fetch choices from web? Here is example on our siteThanks, Alex
SurveyJS Team