- Posts: 22
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
unique(self.NAOK)
{if(!unique(self.NAOK), 'No duplicate rankings.', '')}
Why do you need that if the unique() validation works?Is it also possible to erase a previously given answer in a subquestion if a participant choose the same answer in another subquestion, i.e. if a participant tries to give the same ranking to another subquestion
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define some "Choose" text var choosetext = 'Please choose...'; // Number of visible rows var rowCount = $('tr.answer-item:visible', thisQuestion).length; // Loop through all drop-downs $('tr.answer-item select', thisQuestion).each(function(i) { // Reset if value is above the number of visible rows if($(this).val() > rowCount) { $(this).prepend('<option value="">'+choosetext+'</option>').val(''); checkconditions(this.value, this.name, this.type); } // Remove all unnecessary options $('option', this).filter(function() { return this.value > rowCount; }).remove(); }); }); </script>
...is it possible to mark the subquestions with the same rankings in red?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define some "Choose" text var choosetext = 'Please choose...'; // Number of visible rows var rowCount = $('tr.answer-item:visible', thisQuestion).length; // Loop through all drop-downs $('tr.answer-item select', thisQuestion).each(function(i) { // Reset if value is above the number of visible rows if($(this).val() > rowCount) { $(this).prepend('<option value="">'+choosetext+'</option>').val(''); checkconditions(this.value, this.name, this.type); } // Remove all unnecessary options $('option', this).filter(function() { return this.value > rowCount; }).remove(); }); // Listener on the dropdowns $('tr.answer-item select', thisQuestion).on('change', function(e) { // Handle non-unique answers handleDuplicates(); }); function handleDuplicates() { $('.question-item', thisQuestion).removeClass('duplicate-row'); $('tr.answer-item select', thisQuestion).each(function(i) { if(!$(this).closest('.question-item').hasClass('duplicate-row') && $(this).val() != '') { var thisSelect = $(this); var selectedValue = $(this).val(); $('tr.answer-item select', thisQuestion).not(this).each(function(i) { if($(this).val() == selectedValue) { $(this).closest('.question-item').addClass('duplicate-row'); $(thisSelect).closest('.question-item').addClass('duplicate-row'); } }); } }); } handleDuplicates(); }); </script>
.duplicate-row { background-color: #E74C3C; } .duplicate-row .answertext { color: #FFFFFF; }
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define some "Choose" text var choosetext = 'Please choose...'; // Number of visible rows var rowCount = $('tr.answer-item:visible', thisQuestion).length; // Loop through all drop-downs $('tr.answer-item select', thisQuestion).each(function(i) { // Reset if value is above the number of visible rows if($(this).val() > rowCount) { $(this).prepend('<option value="">'+choosetext+'</option>').val(''); checkconditions(this.value, this.name, this.type); } // Remove all unnecessary options $('option', this).filter(function() { return this.value > rowCount; }).remove(); }); // Listener on the dropdowns $('tr.answer-item select', thisQuestion).on('change', function(e) { // Handle non-unique answers handleDuplicates(); }); function handleDuplicates() { $('.question-item', thisQuestion).removeClass('duplicate-row'); $('tr.answer-item select', thisQuestion).each(function(i) { if(!$(this).closest('.question-item').hasClass('duplicate-row') && $(this).val() != '') { var thisSelect = $(this); var selectedValue = $(this).val(); $('tr.answer-item select', thisQuestion).not(this).each(function(i) { if($(this).val() == selectedValue) { $(this).closest('.question-item').addClass('duplicate-row'); $(thisSelect).closest('.question-item').addClass('duplicate-row'); } }); } }); } handleDuplicates(); //Insert new style rules var newStyle = '<style type="text/css">\ .duplicate-row {\ background-color: #E74C3C;\ }\ .duplicate-row .answertext {\ color: #FFFFFF;\ }\ </style>'; $("head link[rel='stylesheet']").last().after(newStyle); }); </script>