How can I make H5P save answers for items

dnote's picture
Forums: 

Take for example a multiple choice question.

The first time I display the item I want the student to select a choice and press "Check".

My backend will then store the score via LTI.

The next time I display the item I want the student not to be able to select a choice, but instead I want H5P to display the choice the student selected previously.

Is this possbile?

I'm accessing H5P through my website with its own LTI connection but when testing this from Canvas I see the same behaviour.

Dave

   
BV52's picture

Hi Dave,

The "save content state"  provides one half of what you are looking for which is it saves the answers of the students but it does not "lock" them. Also this is only available if you use one of the plugins created for Moodle, Wordpress or Drupal.

-BV

dnote's picture

Hi BV52, thanks for responding. I will move away from LTI for now then and create my own H5P player for .net. That way I can keep control over all aspects.

 
dnote's picture

Hi again. I gotten a little bit further and am now able to show answers previously records by filling the H5PIntegration.contents[x].contentUserData when rendering the page the second time.

The previously filled in answers are selected, but the problem is, they can still by modified by the user. Is it possible to show the content in "solution mode"?

So this:

Instead of this:

Thanks a lot!

Dave

 
otacke's picture

Hi Dave!

I think that most question-like content types implement the question type contract (https://h5p.org/documentation/developers/contracts), so you should be able to check for the showSolutions function and call it.

Best,

Oliver 

dnote's picture

Hi Oliver, thanks. Seems simple enough. But how do I get the instance of the content right after it's being displayed? The first xAPI event (which passes the instance) is too early to do anything with it.

 
otacke's picture

Hi Dave!

You can add your own script to accompany content types using the alter-scripts hook (cmp. https://h5p.org/node/2692). That script will run right away, can wait for content to be initialized (you can e.g. pick up the "initialized" event from H5P.externalDispatcher), add listeners, etc.

Best,
Oliver

dnote's picture

Thanks for your input. I ended up using the initialized event of the external dispatcher which seemed simpler than using the alter-scripts hook:

// After initialization, put the content items that are previously finished in "solution mode". H5P.externalDispatcher.on('initialized', function (_event) {     for (var i = 0; i < instances.length; i++)     {         const instance = instances[i];         if (window.H5PCompleted[instance.contentId])         {             if (instance.showSolutions)             {                 instance.showSolutions();             }         }     } });