Check out the LimeSurvey source code on GitHub!

Multiple short text with some fields mandatory

More
5 years 3 weeks ago #73315 by misterdot
Hi,
I'm trying create a multiple short text question where some of the fields will be mandatory and others won't. So for the address question below, I'd like for all the fields to be required EXCEPT address 2 and county. I'm using the check validity workaround and trying to make it match on anything, but am not having any success. If I leave the field blank, it doesn't seem to do any regex check. Is there a better way to make some of the fields mandatory?

Attachments:

Please Log in to join the conversation.

More
5 years 3 weeks ago #73316 by Mazi
Can you post a link to the survey so we can check the adjusted code and field IDs?


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 weeks ago #73320 by misterdot
Yep, here's a Demo:
dms.sph.sc.edu/limesurvey/index.php?sid=97419

Note that the current regex is /^[0-9]$/ -- if I enter an A-Z letter, the rule works correctly and tells me to enter something else. If I leave it blank, the rule does not complain and it advances. I've also attached the survey.

File Attachment:

File Name: limesurvey...7419.lss
File Size:28 KB


Thanks,
Matt
Attachments:

Please Log in to join the conversation.

More
5 years 2 weeks ago - 5 years 2 weeks ago #73341 by DenisChenu
Hello,

Need some javascript validation.
$(document).ready(function(){
  $('#movenextbtn').click(function(){
    var needAnswer=false;
    if ($("#answer97419X60X853addr1").val()==""){
      needAnswer=true;
      $("#answer97419X60X853addr1").css('background','red');
      }
    if ($("#answer97419X60X853city").val()==""){
      needAnswer=true;
      $("#answer97419X60X853city").css('background','red');
      }
    if ($("#answer97419X60X853state").val()==""){
      needAnswer=true;
      $("#answer97419X60X853state").css('background','red');
      }
    if ($("#answer97419X60X853zip").val()==""){
      needAnswer=true;
      $("#answer97419X60X853zip").css('background','red');
      }
    if (needAnswer){
    alert ('Some answer needed');
      return false;
    }else{
      return true;
    }
  });
});

Look at the documentation for javascript :
docs.limesurvey.org/Workarounds%3A+Manip..._etc._in_LimeSurvey_

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
Last Edit: 5 years 2 weeks ago by DenisChenu.

Please Log in to join the conversation.

More
5 years 2 weeks ago #73358 by Mazi
Which Limesurvey version do you use?


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73438 by misterdot
Thanks! I'm using 1.91 12170. The javascript validation code works perfectly. Since my production survey is only one page, I substituted #movesubmitbtn for #movenextbtn -- otherwise all works great out of the box.
-Matt

Please Log in to join the conversation.

More
5 years 2 weeks ago #73452 by Mazi
Hmm, I don't know what is wrong here but I'm no JS expert. Let's wait for user tpartner to have a look.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73477 by tpartner
Matt, are you still having problems or did Shnoulle's code work when applied to the submit button?

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.

More
5 years 2 weeks ago #73496 by misterdot
No, I'm good. Shnoulle's code did the trick. Thanks, all!

Please Log in to join the conversation.

More
5 years 2 weeks ago #73514 by Mazi
You're welcome!


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form