Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Multiple choice and block selecting more then max

  • Georeatri_106344
  • Georeatri_106344's Avatar
  • New Member
  • New Member
More
6 years 11 months ago #173290 by Georeatri_106344
Replied by Georeatri_106344 on 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:
<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>
The topic has been locked.
More
6 years 11 months ago - 6 years 11 months ago #173292 by tpartner
I think you will also want to change the submit listener as there is no #movenextbtn element anymore.

Maybe this...

Code:
$('#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: 6 years 11 months ago by tpartner.
The topic has been locked.
More
6 years 11 months 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
The topic has been locked.
More
6 years 11 months 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.
The topic has been locked.
More
6 years 11 months 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
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose