Finish button at the question set

Forums: 

Hi everyone,

I'm currently working with the H5P plugin in WordPress on my localhost environment. I'm facing an issue with the finish button, which currently appears only when all questions are answered. I need it to be visible at all times, allowing users to finish the question set even if not all questions are answered (let students to skip some questions).

If anyone has experience dealing with this situation or could provide guidance on ensuring the finish button is always present I would greatly appreciate it.

Thank you!

Summary: 
Finish button is only appearing if all questions are answered, need it to be always visible
Content types: 
otacke's picture

Hi!

This will either require overriding some of the functionality of Question Set using the alter_scripts hook (see https://h5p.org/node/2692 and sub pages for details on customizing) or even forking the content type, because not everything that would need to be overridden might be exposed.

Best,
Oliver

Thank you, alter_scripts hook helped!

otacke's picture

Please feel free to share your solution as well in case others want to achieve the same. Open source is a give-and-take thing.

I created h5pmods.php file, added it to new folder 'h5pmods' (which was created in 'plugins' directory). Then created alter_scripts hook function h5pmods_alter_scripts(&$scripts, $libraries) {
if (isset($libraries['H5P.QuestionSet'])) {
$scripts[] = (object) array(
'path' => '/custom-questionset.js',
'version' => '?ver=1.2.3'
);
}
}
add_action('h5p_alter_library_scripts', 'h5pmods_alter_scripts', 10, 3);

edited custom-questionset.js file (disabled hideButton('finish)) and then activated created plugin (h5pmods) in wordpress.

This really helped: https://github.com/h5p/h5pmods-wordpress-plugin/blob/master/h5pmods.php#...

otacke's picture

I guess the interesting information would be in custom-questionset.js :-)

var _updateButtons = function () {
if (params.disableBackwardsNavigation) {
if (questionInstances[currentQuestion].getAnswerGiven() &&
questionInstances.length-1 !== currentQuestion) {
questionInstances[currentQuestion].showButton('next');
}
else {
questionInstances[currentQuestion].hideButton('next');
}
}
if (questionInstances[currentQuestion]) {
questionInstances[currentQuestion].showButton('finish');
}
};

This is a modified version of original function from questionset.js