Multiple choice and block selecting more then max

More
3 weeks 19 hours ago #173290 by JeeWee
JeeWee replied the topic: Multiple choice and block selecting more then max
It was late last night, so I forgot to mention I changed more then just the checkMax function in order to get it to work under LimeSurvey 3. In case anyone uses the search, this is the full code:

[code type="javascript]
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {

// Maximun answers
var maxAnswers = 2;

// Identify this question
var thisQuestion = $('#question{QID}');

function checkMax() {
$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
if($("input:checked", thisQuestion).length >= maxAnswers) {
$('input[type="checkbox"]', thisQuestion).not(':checked').prop('disabled', true);
}
}

// Initial checkbox states
checkMax();

// Listener on the checkboxes
$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
checkMax();
});

// Remove any "disabled" properties before submitting
$('#movenextbtn, #movesubmitbtn').bind('click', function () {
$('input[type="checkbox"]', thisQuestion).prop('disabled', false);
});

});
</script>
[/code]
The following user(s) said Thank You: stephanied

Please Log in or Create an account to join the conversation.

More
3 weeks 16 hours ago - 3 weeks 16 hours ago #173292 by tpartner
tpartner replied the topic: Multiple choice and block selecting more then max
I think you will also want to change the submit listener as there is no #movenextbtn element anymore.

Maybe this...

$('#limesurvey').on('submit', function(e) {

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 weeks 16 hours ago by tpartner.

Please Log in or Create an account to join the conversation.

More
3 weeks 16 hours ago #173293 by jelo
jelo replied the topic: Multiple choice and block selecting more then max

tpartner wrote: I think you will also want to change the submit listener as there is no #movenextbtn element anymore.

Isn't that a back-step in development? No easy way to check if back or next were clicked, right?

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
3 weeks 15 hours ago #173294 by tpartner
tpartner replied the topic: Multiple choice and block selecting more then max
Yes, you could target the buttons but I find that putting a listener on the form submit event also gets fired with the "Save and resume" function so data is always saved. Of course, it should be tested in individual workarounds (I am on my phone today so can't test).

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
3 weeks 13 hours ago #173298 by jelo
jelo replied the topic: Multiple choice and block selecting more then max

tpartner wrote: Yes, you could target the buttons

Then I got you wrong, I got the impression that it would be no longer possible in LS3.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!