Welcome, Guest
Username: Password: Remember me

TOPIC: Multiple short text with some fields mandatory

Multiple short text with some fields mandatory 2 years 5 months ago #73315

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • 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?

address.jpg
The administrator has disabled public write access.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73316

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
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.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73320

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • 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_survey_97419.lss
File Size: 28 KB


Thanks,
Matt
The administrator has disabled public write access.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73341

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6217
  • Thank you received: 789
  • Karma: 238
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_
Last Edit: 2 years 5 months ago by DenisChenu.
The administrator has disabled public write access.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73358

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
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.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73438

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • 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.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73452

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
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.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73477

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4066
  • Thank you received: 745
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73496

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • 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.

Re: Multiple short text with some fields mandatory 2 years 5 months ago #73514

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
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.
Moderators: ITEd
Time to create page: 0.151 seconds
Donation Image