Welcome to the LimeSurvey Community Forum

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

Alert to Straight Lining

  • modernity4r
  • modernity4r's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 months 3 weeks ago #265096 by modernity4r
Alert to Straight Lining was created by modernity4r
Please help us help you and fill where relevant:
Your LimeSurvey version:  6.5.10+240603 
Own server or LimeSurvey hosting: Both
Survey theme/template: fruity
==================
I created a script to apply to an array type question with 8 sub-questions. I entered it into the source in the HELP section of the question editor, but it does not work. As shown in the attached picture, the warning message appears the first time, but afterwards the 'submit' button does not work. I want the 'submit' button to function after displaying the warning message once, regardless of whether any changes are made. Thank you in advance.

File Attachment:

File Name: limesurvey...7410.lss
File Size:37 KB
 

<script type="text/javascript">
$(document).ready(function(){
    // Array of question codes
    var questions = ;

    // Intercept form submit event
    $('#limesurvey').submit(function(event){
        var sameAnswer = true;
        var firstAnswer = $('#javatbd' + questions[0] + ' .radio input:checked').val();
        
        // Check if the same answer is selected for all questions
        for(var i = 1; i < questions.length; i++) {
            var currentAnswer = $('#javatbd' + questions + ' .radio input:checked').val();
            if(currentAnswer !== firstAnswer) {
                sameAnswer = false;
                break;
            }
        }

        // If the same answer is selected for all questions, display a warning message
        if(sameAnswer) {
            // Check for previous warning message in local storage
            var warned = localStorage.getItem('warnedAboutSameAnswers');
            
            if (warned) {
                // If the warning message has already been seen, allow form submission
                return true;
            } else {
                // If seeing the warning message for the first time, display the warning message and stop form submission
                alert("You have selected the same answer for all questions. Please review your responses.");
                localStorage.setItem('warnedAboutSameAnswers', 'true');
                event.preventDefault(); // Stop form submission
            }
        }
    });
});
</script>

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 months 3 weeks ago #265106 by tpartner
Replied by tpartner on topic Alert to Straight Lining
I don't have access to a computer today but it looks to me like the questions variable is undefined.

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.

  • modernity4r
  • modernity4r's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 months 3 weeks ago - 10 months 3 weeks ago #265109 by modernity4r
Replied by modernity4r on topic Alert to Straight Lining
var questions = ;

I copied the questions variable above to the subject board, but it didn't show up. 

'Q3q1', 'Q3q2', 'Q3q3', 'Q3q4', 'Q3q5', 'Q3q6', 'Q3q7', 'Q3q8'
Last edit: 10 months 3 weeks ago by modernity4r.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 months 2 weeks ago #265134 by Joffm
Replied by Joffm on topic Alert to Straight Lining
Hi,
so this is more or less just a warning - the respondent can proceed without any change.
Why not use a bootstrap alert.

Like





Code:
{if(!is_empty(Q1_001) and countif(Q1_001,self)==6,'<div class="alert alert-danger" role="alert"><strong>Warning!</strong><br/>You have selected the same answer for all questions. Please, review your responses!</div>','')}

Joffm

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

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 months 2 weeks ago #265152 by DenisChenu
Replied by DenisChenu on topic Alert to Straight Lining
And if you need a real confirmation : you can add a mandatory multi choice question with only one choice «I confirm I want to submit like this»

With the good condition to be show
 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: modernity4r

Please Log in to join the conversation.

  • modernity4r
  • modernity4r's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 months 2 weeks ago #265180 by modernity4r
Replied by modernity4r on topic Alert to Straight Lining
Yes, there are multiple ways to do it. In fact, this is a method I use frequently, but using JavaScript and ExpressionScript has made the question heavier. Thank you.

Please Log in to join the conversation.

  • modernity4r
  • modernity4r's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 months 2 weeks ago #265181 by modernity4r
Replied by modernity4r on topic Alert to Straight Lining
I understand the flow of the ExpressionScript you suggested. Thank you. However, I'm not sure if I should put this in the help text editor source of the question editor, in the Relevance equation of the first sub-question, or in some other way. When I put it in the help text editor source, the entire script appears on the screen. I feel really embarrassed.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 months 2 weeks ago - 10 months 2 weeks ago #265183 by Joffm
Replied by Joffm on topic Alert to Straight Lining
Edit:
@Denis was faster
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 10 months 2 weeks ago by Joffm.
The following user(s) said Thank You: modernity4r

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 months 2 weeks ago - 10 months 2 weeks ago #265184 by DenisChenu
Replied by DenisChenu on topic Alert to Straight Lining
Working solution


Condition here :
Code:
countif(Q00_SQ001.NAOK,that.Q00.NAOK) == count(that.Q00.question)  and !is_empty(Q00_SQ001.NAOK)

 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 10 months 2 weeks ago by DenisChenu.
The following user(s) said Thank You: modernity4r

Please Log in to join the conversation.

  • modernity4r
  • modernity4r's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 months 2 weeks ago #265227 by modernity4r
Replied by modernity4r on topic Alert to Straight Lining
Thank you, @DenisChenu, @joffm. So, grouping two questions into one question group is also used in such situations.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose