Welcome to the LimeSurvey Community Forum

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

Random Array (Number) Checkbox with the last two rows fixed AND exclusive

  • philemmons
  • philemmons's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago #242244 by philemmons
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hi all!  
Please would someone be able to help me with this, as I have found variations of one last row fixed with exclusive column, but have failed to get it working properly?  I'm using  Version 3.28.54  
Thank you in advance!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #242246 by Joffm
Which variations did you find and where?
Why didn't you provide the links?
​​​​​​

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • philemmons
  • philemmons's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago - 1 year 6 months ago #242247 by philemmons
Well, I'm new, here is the code I was tweaking with, and it's one ofmany snippets in my LS toolbox.

Thanks Joffm for the quick reply!
Code:
<script type="text/javascript" charset="utf-8">    
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify this question
        var qID = '{QID}';
        var thisQuestion = $('#question'+qID);
 
        // Assign column-specific attributes and classnames
        $('tr.subquestion-list', thisQuestion).each(function(i) {
            $('> *', this).each(function(i) {
                $(this).attr('data-column', i);
            });
        });
        $('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
        // A function to un-check boxes
        function resetCheckbox(thisItem) {
            $(':hidden', thisItem).val('');
            $(':checkbox', thisItem).prop('checked', false).trigger('change');
        }
 
        // Listener on the checkboxes
        $(':checkbox', thisQuestion).on('change', function(e) {
            if($(this).is(':checked')) {
                var thisItem = $(this).closest('.answer-item');
                var thisColumn = $(thisItem).attr('data-column');
                var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
                if($(thisItem).hasClass('exclusive-item')) {
                    items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
                }
                $.each(items, function(i, el) {
                    resetCheckbox(el);
                });
            }
        });
 
        // The subquestion code to place in the last position
        var fixedCode = 'A8';
 
        // Move the "fixed" row to the end
        $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]'));
 
        // Fix up the array row background colours
        $('tr.answers-list', thisQuestion).each(function(i){
            $(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
        });
    });
</script>
Last edit: 1 year 6 months ago by philemmons.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #242250 by Joffm
Hi, obviously you used this tpartner's script
[url] forums.limesurvey.org/index.php/forum/ca...hers?start=12#208891 [/url]

You are right. The exclusive part doesn't seem to work properly.

But this is easy to handle,
Move the "fixed code" part to the top of the script
Code:
        
...
        // Identify this question
        var qID = '{QID}';
        var thisQuestion = $('#question'+qID);
 
        // The subquestion code to place in the last position
        var fixedCode = 'Y010';
 
        // Move the "fixed" row to the end
        $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]'));
 
        // Assign column-specific attributes and classnames
...
 

File Attachment:

File Name: limesurvey...7873.lss
File Size:26 KB

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, philemmons

Please Log in to join the conversation.

  • philemmons
  • philemmons's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago #242399 by philemmons
Thanks Joffm! So would there be a cleaner way to have the last 2 rows be discrete and fixed besides doubling the code and changing the variables?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago - 1 year 6 months ago #242418 by Joffm
Sorry,
where so you "double the code"?
And where do you "change variables"?

Do you talk about several questions where you enter this script?
​​​​​
Joffm

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

Please Log in to join the conversation.

  • philemmons
  • philemmons's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago - 1 year 6 months ago #242421 by philemmons
Thanks for the follow up question. Well my goal is to have two rows fixed and either one enable the exclusion of the column, and this does one row currently. The discrete occurs when both are checked instead of either one. An iteration would be more efficient, but I want to be direct so it would allow more flexibility besides the last two rows in the future. This section would be moved to the top.  
Code:
      // The subquestion code to place in the last and in second to last position
        var [b]fixedCode1 [/b]= 'Ysecond2lastRow';
        var [b]fixedCode2[/b] = 'YlastRow';
 
        // Move the "fixed" row to the second to the last position
        $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+[b]fixedCode1[/b]+'"]'));        // The subquestion code to place in the last position
    
        // Move the "fixed" row to the end
        $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+[b]fixedCode2[/b]+'"]'));
Last edit: 1 year 6 months ago by philemmons.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose