Welcome to the LimeSurvey Community Forum

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

Implement a warning message for non-mandatory questions

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 months 1 week ago #254677 by ngolub
Please help us help you and fill where relevant:
Your LimeSurvey version: Community Edition   Version 6.4.0+231218 
Own server or LimeSurvey hosting: University hosting
Survey theme/template: Bootstrap Vanilla
==================
Hello, I want to implement a feature that enhances the user experience. Specifically, I want to create a warning message that activates when participants click the "Next" button to proceed to the following page. This message should alert them if they haven't answered all the questions on the current page, asking for confirmation if they wish to continue despite unanswered questions. I aim to ensure missing questions are due to a conscious decision rather than oversight without enforcing mandatory responses. Could you provide guidance or suggestions on how to implement this warning mechanism in a user-friendly manner effectively?

I have tried to insert this code in the custom.js of my template (replacing with my actual code ID):

$(document).on('click', '#movenextbtn, #movesubmitbtn', function() {
var unanswered = false;
var questionsToCheck = [
'#questionID1', // Replace with the actual ID of your multiple choice question
'#questionID2', // Replace with the ID of your conditional multiple choice question
'#questionID3', // Replace with the ID of your array text question
'#questionID4', // Replace with the ID of your short free text question
'#questionID5' // Replace with the ID of your numerical input question
];

questionsToCheck.forEach(function(question) {
if ($(question).is(':visible')) {
if ($(question).find('input:checked, input:text[value!=""], textarea[value!=""]').length == 0) {
unanswered = true;
}
}
});

if (unanswered) {
return confirm('You may have missed answering one or more questions. Do you still want to proceed?');
}
});

However, it had no effect. Where should I place the js code, and what would get me the desired result?

Thank you!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago #254682 by Joffm
Hi,
this is a built-in feature "soft mandatory"
 

And seeing your code I see that you use wrong ID of the button.
These do not exist anymore (since LimeSurvey was based on bootstrap long time ago)

Now the ID is "ls-button-submit"

Joffm

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

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 months 1 week ago - 3 months 1 week ago #254685 by ngolub
Thank you very much! This is precisely what I was looking for.

How can I change the text that appears in the warning message (pop-up), and how can I change the text in red that appears next to the red exclamation mark below the question?

EDIT: I was able to change the text that appears in the warning message (pop-up) using the solution provided here:  forums.limesurvey.org/forum/design-issue...soft-warning-message

However, I still cannot change the text in red that appears next to the red exclamation mark below the question.
Last edit: 3 months 1 week ago by ngolub. Reason: error found

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago #254698 by holch
What do you want to change it to? Or is it about the English?

In this case, this string is probably not translated in the German version yet. You can help translating strings here: translate.limesurvey.org.

Once the translation is improved it will make it into the next update and will automatically show up in your installation as well.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 months 1 week ago - 3 months 1 week ago #254702 by ngolub
Thank you. I was not completely clear about what I wanted.

I receive two warning messages for soft-mandatory questions.

I have customized the top one to appear for every question if a participants leaves it empty.

Now I want to completely remove the second warning message: "Bitte wählen Sie mindestens eine Option aus." and "Bitte beantworten Sie alle Bereiche/Teile der Frage(n)". However, I cannot figure out how to do that.

Here is the code I am using for my question group:

<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Define some text strings
    var originalModalText = "Eine oder mehrere Fragen sind noch nicht beantwortet. Bitte diese zuerst beantworten, um zu nächsten Seite gehen zu können!";
    var newModalText = "Es scheint, als hätten Sie nicht alle Fragen beantwortet. Möchten Sie trotzdem fortfahren?";
    var originalTipText="Please notice you haven't answered this question. Still, you can continue without answering.";
    var newTipText="Sie haben diese Frage nocht nicht beantwortet."
 
    // Modify the modal text
    var modalBody = $('.modal-body p').filter(function() {
      return $.trim($(this).text()) == originalModalText;
    });
    if(modalBody.length > 0) {
      modalBody.text(newModalText);
    }
 
    // Identify the tip element(s)
    var oWarnings = $('.ls-question-mandatory').filter(function() {
      return $.trim($(this).text()) == originalTipText;
    });
 
    if (oWarnings.length > 0) {
 
      // Clone the icon span
      var spanEl = $('span:eq(0)', oWarnings.first()).clone();
 
      // Replace the tip text and icon span
      oWarnings.text(' '+newTipText).prepend(spanEl);
    }
  });
</script>

 
Last edit: 3 months 1 week ago by ngolub.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago - 3 months 1 week ago #254709 by Joffm
Did you investigate with your webdevdelopment tool?

You will see which classes ara involved.

In this case (multiple) it is
Code:
<style type="text/css">
div.ls-question-mandatory-multiplechoice {
  display:none;
}
</style>

 

and the original
 

So you have to investigate and adapt.
Unfortunately both messages are placed in the same container.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 months 1 week ago by Joffm.
The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 months 1 week ago #254710 by ngolub
Thank you this worked!

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose