Bootstrap switch quiz question

Bootstrap switch quiz question

by Eli Braddock -
Number of replies: 5

Hi,

I am trying to theme up the matching question with the bootstrap switch.

I am having no trouble getting that part working, but I have been going through the code for so long now and I am sinking in it...

I was hoping someone could help point out where I can test the state of the toggle, true/false against they answer of the sub question and whether they are true or false?

Thank you so very much in advance!


I am using Moodle 2.5.2 as well...

Eli

Attachment subqswitch.jpg
Average of ratings: -
In reply to Eli Braddock

Re: Bootstrap switch quiz question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry, I don't understand your question.

Where do you want to do this test? In the PHP code on the server or in JavaScript in the browser?

When do you want to do it? When the question is displayed, or when the response is submitted?

In reply to Tim Hunt

Re: Bootstrap switch quiz question

by Eli Braddock -

Hi Tim,

My apologies.

I have been trying to find where to do it when the response is submitted but I have so much else on my plate that I keep getting distracted from it so I am unsure of where that might or even if I have to run the logic first and then pass the answer along...

I am just not sure at this point sorry...

In reply to Tim Hunt

Re: Bootstrap switch quiz question

by Eli Braddock -

Perhaps the question I should be asking is if I get the selected state of the switch toggle which will be either true or false in js for the question type when answered by the user, how do I send that on to the quiz as the response for it to mark off as normal?

In reply to Eli Braddock

Re: Bootstrap switch quiz question

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, you need to look how the data is passed back to Moodle.

In a normal matching question, the choices is a <select> like

<select name="q1965:1_sub0">
<option selected="selected" value="0">Choose...</option>
<option value="1">No</option>
<option value="2">Yes</option>
</select>

So, to replace that with a jQuery switch, you need to make sure the the switch eventually submits the same form-date (a value named q1965:1_sub0, with value 0, 1 or 2.

One way to do that is to have a hidden input:

<input type="hidden" name="q1965:1_sub0" value="0">
then have your javascript update the value of that as necessary when the user changes the switch value.