Multiple choice and block selecting more then max

More
7 months 3 weeks ago #173290 by JeeWee
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
7 months 3 weeks ago - 7 months 3 weeks ago #173292 by tpartner
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: 7 months 3 weeks ago by tpartner.

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

More
7 months 3 weeks ago #173293 by jelo

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?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

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

More
7 months 3 weeks ago #173294 by tpartner
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
7 months 3 weeks ago #173298 by jelo

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.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

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!