Picture of Renan Jon Manuel
Modifying MCQ choices
by Renan Jon Manuel - Tuesday, 7 January 2020, 11:31 PM
 

Hi everyone,
Is it possible to change the choices of one mcq component based on the answers from a previous mcq component?

I tried changing it by setting variables then have a 

Adapt.findById('c-lvl01').set('_items', ''[{"text":"First","_shouldBeSelected":false,"feedback":""},{"text":"Second","_shouldBeSelected":false,"feedback":""},{"text":"Third","_shouldBeSelected":false,"feedback":""}],);
 
somewhere down the code, but it doesnt do anything, I tried changing the body using the same principle and I was able to make it work, is it not possible to change the set of choices on the _items?

thank you.
Picture of Matt Leathes
Re: Modifying MCQ choices
by Matt Leathes - Wednesday, 8 January 2020, 10:00 AM
 

When asking questions like this please could you include the version number of the Adapt Framework (and any relevant components) you're using?

Picture of Renan Jon Manuel
Re: Modifying MCQ choices
by Renan Jon Manuel - Wednesday, 8 January 2020, 11:55 PM
 

Hi I'm sorry Im using Adapt Framework v4.0.1 and components used are just MCQ and text.

Picture of Matt Leathes
Re: Modifying MCQ choices
by Matt Leathes - Thursday, 9 January 2020, 3:32 PM
 

OK so first off, it may just be a copy-paste error but the sample line of code you supplied:

Adapt.findById('c-lvl01').set('_items', ''[{"text":"First","_shouldBeSelected":false,"feedback":""},{"text":"Second","_shouldBeSelected":false,"feedback":""},{"text":"Third","_shouldBeSelected":false,"feedback":""}],);

Isn't quite right in that you have quotes before the opening [ character - and a trailing comma after the closing ] character.

But even with that corrected it still might not work. Unfortunately you don't say what version of MCQ you're using - but assuming it's v3.0.0 then the _items get read into a data model (itemsQuestionModel.js) that handles a lot of the shared logic used by multiple choice questions. So you'll need to force it to 'refresh' that with the new data.

A VERY cursory bit of hacking around with this suggests that calling the setupItems method of the model looks like it might work - but that needs significantly more testing to check there's no knock-on effects. I didn't have much involvement in the work to add this new data model so I'm not as familiar with how it works as others might be.

If the MCQ you're trying to change is on the same page as the one that changes it, you're also going to need to force the component to re-render to pick up the changes as, unfortunately, changing the data model in Backbone applications doesn't automatically update the view like you'd expect if you're using to working with VueJS or React.

If you also need the learner's choice of answers to be remembered 'between sessions' (see the _shouldStoreResponses setting of the spoor extension)  - I have no idea if that would work given what you're doing!

Instead of trying to change an existing MCQ, a better option might be to have multiple instances of the MCQ - and to use the _isAvailable property to hide the ones you don't want and show the ones you do?