Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Multiple Choice with comments - sum validation problems

  • dangerdangerhighvoltage
  • dangerdangerhighvoltage's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 2 weeks ago #251004 by dangerdangerhighvoltage
Multiple Choice with comments - sum validation problems was created by dangerdangerhighvoltage
Your LimeSurvey version: 6.1.6+230703
Own server or LimeSurvey hosting: own server
Survey theme/template: bootswatch
==================
Hello fellow Limesurvey enjoyers.

I used a "Multiple choice with comments"-question with a javascript to hide the last 2 text fields and if either of the first two options are chosen they need a validation sum of 100, if neither of those options are chosen, the sum validation shouldn't trigger. I tried my hardest, but my lack of knowledge with regex and validation equation in general is showing. I got the sum check to work, but i don't know how to "deactivate" the sumcheck if the last 2 options are chosen.

I attached the lss for you all to check on my mediocre attempt.

The validation attempt:
"if(
    (is_empty(f10b_1comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', f10b_1comment.NAOK))
    and
    (is_empty(f10b_2comment.NAOK) or regexMatch('/^[1-9][0-9]{0,4}$/', f10b_2comment.NAOK))
    , sum(f10b_1comment.NAOK, f10b_2comment.NAOK) == 100 or f10b_3=='Y' or f10b_4=='Y', ''
)


Thanks for the help in advance. :)


 
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 2 weeks ago #251006 by Joffm
Hi,
You can do this
No need to use the regex, as you calculate a sum (why did you allow numbers up to 10000?)

((f10b_1.NAOK!='Y' and f10b_2.NAOK!='Y') or (sum(f10b_1comment.NAOK,f10b_2comment.NAOK)==100)) or (f10b_3.NAOK=='Y' or f10b_4.NAOK=='Y')

To avoid an initial error - as long as no checkbox is selected - the first part.
So, either both checkboxes are not selected or the sum is 100 - or one of the last two checkboxes is selected. 

And a validation tip like
{if(f10b_3.NAOK=="Y" or f10b_4.NAOK=="Y","","Nur Zahlen und Summe muss 100 ergeben!")}
 

 

 

And to avoid this confusing message
 
you may add this to your css.
And it is not necessary to double the scripts.
Sufficient:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Remove the first comment box
    $('#question{QID} ul.ls-answers li:eq(2) .comment-item').remove();
    $('#question{QID} ul.ls-answers li:eq(3) .comment-item').remove();
  });
</script>
<style type="text/css">
  #question{QID} input[type="text"] {
    width: auto;
    display: inline-block;
  }
  div.em_commented_checkbox {
    display:none;
  }
</style>

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: dangerdangerhighvoltage

Please Log in to join the conversation.

  • dangerdangerhighvoltage
  • dangerdangerhighvoltage's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 2 weeks ago #251031 by dangerdangerhighvoltage
Replied by dangerdangerhighvoltage on topic Multiple Choice with comments - sum validation problems
>No need to use the regex, as you calculate a sum (why did you allow numbers up to 10000?)

Because my attempt at making this work was a Frankenstein creation of different google searches without understanding regex at all. :P


Thanks a lot!

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose