choicesByUrl should save raw data
See original GitHub issueAre you requesting a feature, reporting a bug or asking a question?
question/feature
What is the current behavior?
my original need was a way to fetch remote object prop in order to populate other questions after selecting that object from a dropdown. I managed to do it by a custom asyn func called getRemoteObjectProperty as suggested by your example (which is, by the way, very similar to Expression Trigger)
However, even if that methodology is very useful in general when I use dropdown with choicesByUrl, the remote service often returns array of objects with all their props. Theoretically there shouldn’t be the need to run the second request in order to fetch the desired object and then its prop as SurveyJS already bumped into it while loading choices from remote.
I, actually, also managed to avoid the second request by an hack which I don’t really like:
https://plnkr.co/edit/RhW7K4lislPHOFeQ?preview
I don’t like the following even if it’s clear and works
survey.onLoadChoicesFromServer.add(function(survey,options) {
options.question.valueObject = options.serverResult
})
Maybe tying valueObject directly to question is wrong. To avoid this I thought about a native solution that will let me access valueObject prop in the ItemValue class as I know you can add custom prop to itemvalue class doing something like :
Survey.Serializer.addProperty("itemvalue",
{ name: "alpha3Code" }
);
but this is hardcoded and I was not able to add the whole valueObject prop that will let me simplify the custom function much more:
https://plnkr.co/edit/SCQaTYKhbYJzfSAW (read the comment at line 14)
Is there a way to attach the whole remote object to the selected item value so that I will enable my users to select which prop insert directly by the json model?
thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (14 by maintainers)
Top GitHub Comments
I’ve found the issue. Items were copied but originalItem was not. I’ve added unit test and fixed it. Hope this finally makes it work.
@masciugo am I right that in display mode you can’t access addiotional parameters for the selected object? As far as i understand in display mode you already have the data you assign to survey. Can you at this moment (probably even on the sever side) obtain the additional parameters you need?
You can use the survey.data in the getSelectedChoiceProp function as data source for the display mode… The first idea 😃