Skip to content
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

Custom dropdown Data Source #51

Closed
mfarazkhan opened this issue Aug 18, 2016 · 8 comments
Closed

Custom dropdown Data Source #51

mfarazkhan opened this issue Aug 18, 2016 · 8 comments

Comments

@mfarazkhan
Copy link

Hi,

i am trying to achieve a custom data source for dropdown components, which will help dropdown to be populated from a different data source rather than defining in the editor.
please have a look at the below changes, confirm if this is the right place or will it cause some other problems.
Object.defineProperty(n.prototype, "choices", {
get: function () {
debugger;
//"dataServiceURL" is a new property in dropdown property bag.
if (this.dataServiceURL != undefined) {
this.choicesValues = []; //reinitialize the Array
//loading with a different source.
this.choices = ["1|1st modified Item", "2|2nd Modified Item"];
console.log(this.choicesValues);
return this.choicesValues;
} else {
return this.choicesValues
}
},
set: function (t) {
debugger;
e.ItemValue.setData(this.choicesValues, t)
}

@andrewtelnov andrewtelnov changed the title Custom dropdown Data Soruce Custom dropdown Data Source Sep 8, 2016
@andrewtelnov
Copy link
Member

Please refer to this issue: #67

@andrewtelnov
Copy link
Member

Hi,
I have implemented the first variant of the feature. Could you check it out?
I am going to work on property editor now. I also thinking about having a parameter support in the url. For example, when you have the employee list and you may show it only after the person select the department. So you do not show the full list, but filtered by a parameter, previous answered question value. Do you need this?

Thank you,
Andrew

@andrewtelnov
Copy link
Member

@PankajKumawat125
Copy link

PankajKumawat125 commented Apr 12, 2018

Hi,
Can i call a function in js instead of URL for fetching data and bind with dropdown?

@andrewtelnov
Copy link
Member

@PankajKumawat125 you may get a question and set the choices:
var question = survey.getQuestionByName("myQuestionName");

question.choices = [1, 2];
//or 
question.choices = [{value: 1, text: "item 1"}, {value: 2, text: "item 2"}];

Thank you,
Andrew

@PankajKumawat125
Copy link

@andrewtelnov Perfect. work fine.
Can you help me with one more thing ?
If i want to pre-select one of the value and show the dropdown then How do i do that?

@andrewtelnov
Copy link
Member

@PankajKumawat125 survey.setValue("YourQuestionName", defaultValue); example
or use the defaultValue property in the question, defaultValue: yourDefaultValue.

Please go through our demos. You are asking very basic questions.

Thank you,
Andrew

@PankajKumawat125
Copy link

@andrewtelnov Well, I have already done that. i was just going to delete my 2nd question.
and
In this case it was fetching dynamically, that is why i asked you this question!
Anyways thank you so much for your help

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

No branches or pull requests

3 participants