Multiple short text with some fields mandatory

More
5 years 9 months ago #73315 by misterdot
misterdot created the topic: Multiple short text with some fields mandatory
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 9 months ago #73316 by Mazi
Mazi replied the topic: Multiple short text with some fields mandatory
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 9 months ago #73320 by misterdot
misterdot replied the topic: Multiple short text with some fields mandatory
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 9 months ago - 5 years 9 months ago #73341 by DenisChenu
DenisChenu replied the topic: Multiple short text with some fields mandatory
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).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 5 years 9 months ago by DenisChenu.

Please Log in to join the conversation.

More
5 years 9 months ago #73358 by Mazi
Mazi replied the topic: Multiple short text with some fields mandatory
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 9 months ago #73438 by misterdot
misterdot replied the topic: Multiple short text with some fields mandatory
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 9 months ago #73452 by Mazi
Mazi replied the topic: Multiple short text with some fields mandatory
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 9 months ago #73477 by tpartner
tpartner replied the topic: Multiple short text with some fields mandatory
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 9 months ago #73496 by misterdot
misterdot replied the topic: Multiple short text with some fields mandatory
No, I'm good. Shnoulle's code did the trick. Thanks, all!

Please Log in to join the conversation.

More
5 years 9 months ago #73514 by Mazi
Mazi replied the topic: Multiple short text with some fields mandatory
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.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!