Welcome to the LimeSurvey Community Forum

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

Exclusive option for "Array (numbers)" / Checkbox Array - mistake in script?

  • matclou
  • matclou's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 months 1 week ago #266220 by matclou
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition Version 6.4.3
Own server or LimeSurvey hosting: Server of a third party / organisation
Survey theme/template:
==================


Dear all,

while programming a new survey I wanted to have exclusive options in a checkbox array ("Array (numbers") - as soon as the last option per row is checked. The issue is pretty much described in this Thread ( forums.limesurvey.org/forum/can-i-do-thi...-an-exclusive-option ) and there is even a solution for this ( forums.limesurvey.org/forum/can-i-do-thi...lusive-option#121763 ).

However when I integrated this script into my question text, it does not work.

I am not sure whether this might have to do with the admin settings which I cannot access in this instance. However, in general JavaScript seems to work.

I attached a sample survey file (which does not work for me) to this message.

Does someone have an Idea what I am missing here?

Best regards

Mathias / matclou

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 1 week ago - 4 months 1 week ago #266223 by Joffm
Hi,
you saw that this script is more than 9 years old and was made for a totally different version?

You may use this
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    // Call the exclude function using question ID
    excludeOpt({QID});
  });
 
  // A function to make the last option in each array row exclusive
  function excludeOpt (qID) {
 
    var thisQuestion = $('#question'+qID)
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normal-item');
    $('tr.subquestion-list', thisQuestion).each(function(i) {
    $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item')
    });
 
    // A listener on the checkboxes
    $('input[type="checkbox"]', thisQuestion).on('change', function (event) {
      handleExclusive($(this).closest('td'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisRow = $(thisCell).closest('tr');
 
      // Uncheck the appropriate boxes in a row
      if ($(thisCell).hasClass('normal-item')) {
        $('.exlusive-item input[type="checkbox"]', thisRow).prop('checked', false);
      }
      else {
        $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false);
      }
 
      // Check conditions (relevance)
      $('td.checkbox-item', thisRow).each(function(i) {
        var thisValue = '';
        if($('input[type="checkbox"]', this).is(':checked')) {
          thisValue = 1;
        }
        var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
        $('input[type="hidden"]', this).attr('value', thisValue);
        fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
      });
    }
  }
</script>


To make the first column exclusive just exchange
$('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item')
by
$('.normal-item:first', this).removeClass('normal-item').addClass('exlusive-item')
Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 months 1 week ago by Joffm.

Please Log in to join the conversation.

More
4 months 3 days ago #266316 by Oterito
Limesurvey version: 6.6.1
LimeSurvey hosting
Theme Fruity
Hi everyone, i am sorry my question is not about this specific topic, but i can't post a new topic because i have no "message box" when i try to create a new one and i really need help.
I have an issue with headers on array numbers with checkboxes on mobile.
I set my question to repeat headers every 6 rows. On web it seems perfect, but on mobile change the visualization and show the row and below the options (columns). When you scroll down after 6 subquestions appears the response options (columns) as a list (like the repeated headers) and its confusing for the respondant. I have an screen shot but i cant upload it here.
Can you help me?
Thanks and sorry for the inconvenience.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 3 days ago - 4 months 3 days ago #266319 by Joffm
@Oterito,
I can reproduce.

What you have to do?
File a bug report!
[url] community.limesurvey.org/bug-tracker/ [/url]
Same credentials as in the forum.

What you ought to do.
If you think a repetition of headers is necessary there seem to be too many items in the array.
As long arrays are one of the main reasons to terminate a survey you should split the array into several pages.

What you can do.
Check the screen width of the participant. There is a script for this in the forum.
On smaller screens the headers are not necessary because shown in the subquestions
On wider screens show additional headers by javascript.




Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 months 3 days ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose