Check out the LimeSurvey source code on GitHub!

Create unique options in array question

More
5 years 11 months ago #57578 by paulfiner
Thanks Tony, it works great!

Cheers

Paul

Please Log in to join the conversation.

More
5 years 11 months ago #57594 by paulfiner
Spoke too soon!

It seems to be a bit erratic when clicking on the options. Sometimes it works correctly and shows the next button after choosing 3 items and other times it doesn't. When it doesn't, you need to select another option before it will show the next button.

This is in Safari on the Mac and my client picked up on it using Explorer on Windows.

Please Log in to join the conversation.

More
5 years 11 months ago #57598 by tpartner

Sometimes it works correctly and shows the next button after choosing 3 items and other times it doesn't.

I don't understand this. What do you mean by "after choosing 3 items"? The script should fire when any radio button is selected.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 11 months ago #57600 by paulfiner
Sorry Tony, I have also applied the workaround here:
docs.limesurvey.org/tiki-index.php?page=...f_an_array_mandatory

To make sure the respondent can't move on until there is a choice in each of the 3 columns.

Sometimes it works correctly othertimes it doesn't.

Please Log in to join the conversation.

More
5 years 11 months ago #57603 by tpartner
So is the problem with the workaround script or the scripts from this forum topic?

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 11 months ago #57604 by paulfiner
I think it's from the workaround script but maybe a combination of the two?
I tried increasing the delay in the Timeout function used in the workaround but it didn't work.

Unfortunately my client wants this survey to go live this afternoon and isn't too happy that this doesn't work. It seems like it should be such a straightforward type of question!

Please Log in to join the conversation.

More
5 years 11 months ago #57605 by tpartner
That workaround is for mandatory rows in a text array. Did you modify it?

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
5 years 11 months ago #57606 by paulfiner
Here's the code I am using:
<script type="text/javascript" charset="utf-8">
 
// Wait until the document is fully loaded
$(document).ready(function() { 
 
    /********************** SETTINGS **********************/
 
    // The text to appear in the warning element 
    var warningText = 'Please answer 3 to continue';
 
    // The question ID 
    var questionId = 2326;
 
    // The minimum number of answers required 
    var minNumber = 3;
 
    /******************************************************/
 
    // Create the warning element and place it after the submit button          
    var el = document.createElement('div'); 
 
    el.setAttribute('id','warning');
 
    document.body.appendChild(el);
 
    $( '#warning' ).css({ 
        'border':'1px solid #333333', 
        'width':'200px', 
        'padding':'3px', 
        'color':'red' 
    });
 
    $('#warning').html(warningText);
 
    $('input[type="submit"]').after($('#warning')); 
 
    // Detect the initial number of checked answers & display Next/Submit button accordingly 
    var inputInitCount = 0; 
 
    $('#question' + questionId + ' input').each(function(i) { 
        if ($( this ).attr('checked') == true ) { 
            inputInitCount++; 
        } 
    }); 
 
    if (inputInitCount > (minNumber - 1)) { 
        $('input[type="submit"]').show(); 
        $('#warning').hide(); 
    } 
    else { 
        $('#warning').show(); 
        $('input[type="submit"]').hide(); 
    } 
 
    // Listener to detect number of checked answers & display Next/Submit button accordingly 
    $('#question' + questionId + ' input').click(function() { 
 
        var inputCount = 0; 
 
        $('#question' + questionId + ' input').each(function(i) { 
            if ($( this ).attr('checked') == true ) { 
                inputCount++;
 
            } 
        });
 
 
 
        if (inputCount > (minNumber - 1)) { 
            $('input[type="submit"]').show(); 
            $('#warning').hide(); 
        } 
        else { 
            $('#warning').show(); 
            $('input[type="submit"]').hide(); 
        }  
 
        // The original functions of the click event 
        checkconditions(this.value, this.name, this.type);
    });                    
});
</script>

I've checked the inputCount variable and it gets incremented but it also gets incremented if a user changes their option in a particular column. The crux of the problem is I just need to count the total number of boxes ticked and proceed if this is 3.

Please Log in to join the conversation.

More
5 years 11 months ago #57607 by paulfiner
I think this workaround might be a bit overkill. I'm going to try a loop and just count the checkboxes before the Next button is pressed.

Please Log in to join the conversation.

More
5 years 11 months ago #57609 by tpartner
Well, that's not the workaround you linked below and it will definitely get screwed up by the timer function in this topic's script and the fact that table cells can be clicked.

I think you just need to interrupt the next/submit function. do a column count and proceed accordingly.

Gimme a minute...

Cheers,
Tony Partner

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

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form