How to add an array of choices (irk-text-choice) for irk-text-choice-question-step
I want to add an array of multiple questions based on dynamic data stored in JSON.
This is how I am trying to do it:
<irk-task>
<irk-text-choice-question-step ng-repeat=item in items style="multiple">
<irk-text-choice text="{{item.text}}" value="{{item.value}}"></irk-text-choice>
</irk-text-choice-question-step>
</irk-task>
It doesn't seem to work.
I tried this which worked but this doesn't allow me to select multiple choices which is crucial to me:
<irk-task>
<irk-text-choice-question-step style='multiple'>
<div ng-repeat=item in items>
<irk-text-choice text='{{item.text}}' value='{{item.value}}'></irk-text-choice>
</div>
</irk-text-choice-question-step>
</irk-task>
In js file in irkTextChoiceQuestionStep in link I am simply doing this:
scope.items = JSON.parse(window.localStorage.interventionData);
This is working fine when I am adding ng-repeat to div but not when I am adding it to irk-text-choice-question-step.
Please refer to the following gist for the proper way to handle dynamic data when building your survey markup:
https://gist.github.com/nicksteffens/56a86a679e4b062341cb79a05105f110
Here's the related issue: https://github.com/ninoguba/ionic-researchKit/issues/17
@mrvipinkashyap does the above address your issue? Let me know either way so we can update the status of this accordingly. Thanks!
@ninoguba Thanks for your quick response last time.
I haven't been able to implement it as per the resource you provided yet. I was looking for a more straightforward way of doing this for now as my requirement at this point was just to add dynamic items from array for just
@mrvipinkashyap I've tried making the following work but unfortunately it doesn't at this time.
<irk-task>
<irk-text-choice-question-step id="q7" title="A multiple choice question." text="Select all that apply." style="multiple">
<irk-text-choice text="{{choice.text}}" value="{{choice.value}}" ng-repeat="choice in choices"></irk-text-choice>
</irk-text-choice-question-step>
</irk-task>
It displays the dynamic choices fine but unfortunately, when you select one choice it selects/deselects all of it. And also the result doesn't get mapped properly. When style="single" is used, it appears and behaves fine in the UI but the choice doesn't get mapped in the results properly as well.
This will take some more of my time to support. Unfortunately I don't have the time right now...
@ninoguba Thank you for updating me. Yes. I tried the same thing and few others. But it doesn't map correctly. Will try to get back to this myself when it becomes unavoidable and I have sufficient time to dedicate to it.