ionic-researchKit icon indicating copy to clipboard operation
ionic-researchKit copied to clipboard

How to add an array of choices (irk-text-choice) for irk-text-choice-question-step

Open vipin1code opened this issue 9 years ago • 5 comments

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.

vipin1code avatar May 09 '16 17:05 vipin1code

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

ninoguba avatar May 09 '16 17:05 ninoguba

@mrvipinkashyap does the above address your issue? Let me know either way so we can update the status of this accordingly. Thanks!

ninoguba avatar May 13 '16 17:05 ninoguba

@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 with multiple select options. If there is no other way of adding iteration to it?

vipin1code avatar May 13 '16 17:05 vipin1code

@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 avatar May 17 '16 19:05 ninoguba

@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.

vipin1code avatar May 17 '16 19:05 vipin1code