Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Multiple short text with some fields mandatory

Multiple short text with some fields mandatory 4 years 7 months ago #73315

  • misterdot
  • misterdot's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Thank you received: 1
  • Karma: 0
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?

The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73316

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6009
  • Thank you received: 370
  • Karma: 260
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)limesurvey.org'"
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73320

  • misterdot
  • misterdot's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73341

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9352
  • Thank you received: 1339
  • Karma: 386
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
Last Edit: 4 years 7 months ago by DenisChenu.
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73358

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6009
  • Thank you received: 370
  • Karma: 260
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)limesurvey.org'"
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73438

  • misterdot
  • misterdot's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73452

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6009
  • Thank you received: 370
  • Karma: 260
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)limesurvey.org'"
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73477

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6313
  • Thank you received: 1407
  • Karma: 546
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.
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73496

  • misterdot
  • misterdot's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Thank you received: 1
  • Karma: 0
No, I'm good. Shnoulle's code did the trick. Thanks, all!
The administrator has disabled public write access.

Multiple short text with some fields mandatory 4 years 7 months ago #73514

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6009
  • Thank you received: 370
  • Karma: 260
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)limesurvey.org'"
The administrator has disabled public write access.
Time to create page: 0.237 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form