Multiple Short Text with some (not all) fields mandatory.

Mehr
4 Monate 1 Woche her #161559 von nique
nique erstellte das Thema Multiple Short Text with some (not all) fields mandatory.
Hi there,

I found this old thread with some JS on making only a few questions mandatory in a multiple short text question.

The select questions as mandatory is working but I am finding that the script is interfering with another question and quotas I have set up.

Q1 asks the level of interest a participant has in our research - Radio List - Yes / No / Someone Else.
Yes / Someone Else triggers Q2 which has the multiple short text question asking for further details.
If someone says No, then they are directed to the end of the survey via a Quota.

The JS for Q2 is somehow interfering with this Quota or Q1 as when I select No - and click next, the same pop up box regarding an answer needed appears. Even though Q2 is never presented to this person.

Could someone please let me know where my code is going wrong?

I tried changing #movenextbtn to #movesubmitbtn but then the code doesn't work at all.
I figure I need some identifying JS regarding 'if this question is presented' but am at a loss.

All help is greatly appreciated.

Here is also my exact code in the survey.
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
  $('#movenextbtn').click(function(){
    var needAnswer=false;
    if ($("#answer448284X2875X55236fn").val()==""){
      needAnswer=true;
      $("#answer448284X2875X55236fn").css('background','red');
      }
    if ($("#answer448284X2875X55236sn").val()==""){
      needAnswer=true;
      $("#answer448284X2875X55236sn").css('background','red');
      }
    if ($("#answer448284X2875X55236org").val()==""){
      needAnswer=true;
      $("#answer448284X2875X55236org").css('background','red');
      }
    if ($("#answer448284X2875X55236ph").val()==""){
      needAnswer=true;
      $("#answer448284X2875X55236ph").css('background','red');
      }
    if ($("#answer448284X2875X55236em").val()==""){
      needAnswer=true;
      $("#answer448284X2875X55236em").css('background','red');
      }
    if (needAnswer){
    alert ('Answer needed');
      return false;
    }else{
      return true;
    }
  });
});
  </script>

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her - 4 Monate 1 Woche her #161570 von Joffm
Joffm antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Hello, nique,
your mentioned thread is 5 years old. So obviously the JS is only working in an outdated version of LS.
We do not know which LS version you are using.

But the easiest way to do what you write in the subject , is:
Question is set to not mandatory.
By subquestion relevance force some fields to be filled
!is_empty(Q1_SQ002) AND !is_empty(Q1_SQ003)



Regards
Joffm
Anhang:
Letzte Änderung: 4 Monate 1 Woche her von Joffm.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161571 von nique
nique antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
I am using LS - Version 2.59.1+170116

I forgot that this newer version allows for relevance equations to be added to subquestions.

If I have 10 multiple short answers, and I only want 4 to be mandatory, do I have to insert this code into each of the ones I want to be mandatory? Just unsure where to place this.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161572 von Joffm
Joffm antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Sorry,
I wrote "subquestion relevance". Of course it is "subquestion validation".

Advanced settings:


Joffm
Anhang:
Folgende Benutzer bedankten sich: nique

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161574 von holch
holch antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Watch out with Joffms code. It will pass if ONE of the subquestions is answered. From what I understood, all 4 must be answered, so I guess you need to use "OR" instead of "AND". But I might also have understood the task wrong.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161578 von Joffm
Joffm antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Holch, please, don't scare me.

The validation is (both subquestions have to be answered):
"The second subquestion is not empty AND The third subquestion is not empty"

If you say "OR", it passes if the second OR the third are not empty.

Joffm

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161581 von holch
holch antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Hmmm, I might be thinking wrong. But if SQ2 and SQ3 are mandatory, they should not be empty, correct? So far so good.

Wait a second. I think I mixed my thinking up with conditions in EM. So basically the message shows if what is in the question validation is not correct. If this is the case, your code is correct. Sorry for the confusion.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161589 von tpartner
tpartner antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
I'm wondering why place it in the Sub-question validation and not in the Question validation.

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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 1 Woche her #161611 von nique
nique antwortete auf das Thema: Multiple Short Text with some (not all) fields mandatory.
Thanks Joffm. This works much better than the old JS I was using.
And you are correct that it is an AND function - all 4 are mandatory and required before proceeding.

Following tpartner's suggestion, I added this into the whole question validation. Appears to be a bit cleaner that way.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha