jewlofthelotus/SlickQuiz

Evaluating an answer without clicking 'Check Answer'

shannpersand opened this issue · 7 comments

Hello! Thanks for putting this plugin out there. I was just wondering if there is an easy way to change the 'Check Answer' action to fire as soon as an option is selected, or if you have any suggestions for immediately evaluating whether the answer is correct/incorrect upon selection.

Hi @shannpersand - There's nothing built in to the plugin that would give you this functionality, but you should definitely be able to set up a new on click event for the answer inputs. You could probably modify or duplicate the event that already exists for the button:

https://github.com/jewlofthelotus/SlickQuiz/blob/master/js/slickQuiz.js#L630

And use the same checkAnswer method, you'll just need to pass that function the button associated with that question, or modify the method to not need it.

Hope that gets you started.

Thanks! I set up a new event and it works perfectly.

Glad to hear it @shannpersand! Thanks for using SlickQuiz!

@shannpersand would you be interested in sharing how you got this to work? I'm interested in doing the same.

@blfeigel sure, it's been a long time since I looked at this, I'm sure this is an incredibly inefficient way to do it:

https://gist.github.com/shannpersand/917535d68df2a26b35fc

You'll probably just have to change the level of selection. I was doing a quiz where the radio buttons would turn red/green on click based on if you got the question right or wrong.

I'm finally back on this and was able to get the correct response to show when you click an answer input, but it seems to have broken the next button.

// Bind "check answer" to any click on answer $(_element + ' ' + _answers).find('input[type=radio]').on('click', function(e) { e.preventDefault(); plugin.method.checkAnswer(this, {callback: plugin.config.animationCallbacks.checkAnswer}); });

Any ideas?

Figured it out, e.preventDefault(); is not needed. In this case it was preventing the input from getting the :clicked attribute, which made the next button logic return false.