Welcome, Guest
Username: Password: Remember me

TOPIC: Create unique options in array question

Re: Create unique options in array question 3 years 4 months ago #57578

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Thanks Tony, it works great!

Cheers

Paul
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57594

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57598

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57600

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57603

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57604

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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!
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57605

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57606

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57607

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 4 months ago #57609

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.147 seconds
Donation Image