Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Validating an Array (Texts)

Validating an Array (Texts) 2 years 2 weeks ago #85176

  • dirend
  • dirend's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
I have used the Array (texts) question type for one of my surveys.
May i know how to validate the percentage subquestion.
Here's what i want to be happened,
If the sum of the entered percentage values gets equal or more than 100 while user enters percentage values, it should give the user a relevant error message or warning.

I think i should put an equation to the Sub-question validation equation Logic field.
But all the equations i tried gave errors in the Logic File. :(

I have uploaded the exported survey file so you could get a proper idea.

Can any one help me on this? :) Thankxx in advance!
Attachments:
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85178

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
You were close.

Use the "Question validation equation" instead of the "Sub-question validation equation". Since you are summing all of the variables in column 2, use this equation to ensure that the sum equals 100:
sum(self.sq_2)==100

When you use Show Logic File, you will see that equation auto-expands to this:
sum(2_A_2, 2_B_2, 2_C_2, 2_D_2, 2_E_2, 2_F_2, 2_G_2, 2_H_2, 2_I_2) == 100
The administrator has disabled public write access.
The following user(s) said Thank You: dirend

Re: Validating an Array (Texts) 2 years 2 weeks ago #85187

  • uwudamit
  • uwudamit's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 1
When i use this in Question validation equation it gave me a error in logic file saying that
it has errors. Here i have attached two images.




one.PNG


two.PNG

Can any one help me on this? Thanks in advance!
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85192

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Which version of 1.92+ are you using? This feature was added in one of the late July or August releases, so you may need to upgrade to the latest 1.92+ release.

If you don't want to upgrade, you can just enter the full equation instead of using the self variable, in which case the "Question validation equation" would be:
sum(2_A_2, 2_B_2, 2_C_2, 2_D_2, 2_E_2, 2_F_2, 2_G_2, 2_H_2, 2_I_2) == 100
The administrator has disabled public write access.
The following user(s) said Thank You: dirend

Re: Validating an Array (Texts) 2 years 2 weeks ago #85195

  • dirend
  • dirend's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
It's Version 1.92+ Build 120418.
Anyway we tried the full equation and it worked! :)
Thank you very much for your support Mr.TMSWhite!
:)
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85196

  • uwudamit
  • uwudamit's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 1
Yes it worked.. :)

Thank you very much...
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85231

  • dirend
  • dirend's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
I got another question in the same survey.It's related to the survey file i'v attached in the first post of this topic.

In that survey file 1st sub query column is Rank.
I want to prevent user from entering the same values again.
How can i allow only unique values in the fields?
Is there any option or equation to do this?

I wan't it to be like this



Not like this

docs.google.com/file/d/0B8JZMxx6Km7oNG5nelVBRjI3WlU/edit
Last Edit: 2 years 2 weeks ago by dirend.
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85233

  • dirend
  • dirend's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
i didn't found any unique value checking operator so i went with a long equation to get the job done. Here's what i used.It worked.Hope someone else might come up with a better solution. :)


(
(Q2_A_J1 != Q2_B_J1) and
(Q2_A_J1 != Q2_C_J1) and
(Q2_A_J1 != Q2_D_J1) and
(Q2_A_J1 != Q2_E_J1) and
(Q2_A_J1 != Q2_F_J1) and
(Q2_A_J1 != Q2_G_J1) and
(Q2_A_J1 != Q2_H_J1) and
(Q2_A_J1 != Q2_I_J1)
) and (
(Q2_B_J1 != Q2_C_J1) and
(Q2_B_J1 != Q2_D_J1) and
(Q2_B_J1 != Q2_E_J1) and
(Q2_B_J1 != Q2_F_J1) and
(Q2_B_J1 != Q2_G_J1) and
(Q2_B_J1 != Q2_H_J1) and
(Q2_B_J1 != Q2_I_J1)
) and (
(Q2_C_J1 != Q2_D_J1) and
(Q2_C_J1 != Q2_E_J1) and
(Q2_C_J1 != Q2_F_J1) and
(Q2_C_J1 != Q2_G_J1) and
(Q2_C_J1 != Q2_H_J1) and
(Q2_C_J1 != Q2_I_J1)
) and (
(Q2_D_J1 != Q2_E_J1) and
(Q2_D_J1 != Q2_F_J1) and
(Q2_D_J1 != Q2_G_J1) and
(Q2_D_J1 != Q2_H_J1) and
(Q2_D_J1 != Q2_I_J1)
) and (
(Q2_E_J1 != Q2_F_J1) and
(Q2_E_J1 != Q2_G_J1) and
(Q2_E_J1 != Q2_H_J1) and
(Q2_E_J1 != Q2_I_J1)
) and (
(Q2_F_J1 != Q2_G_J1) and
(Q2_F_J1 != Q2_H_J1) and
(Q2_F_J1 != Q2_I_J1)
) and (
(Q2_G_J1 != Q2_H_J1) and
(Q2_G_J1 != Q2_I_J1)
) and (
(Q2_H_J1 != Q2_I_J1)
)
The administrator has disabled public write access.

Re: Validating an Array (Texts) 2 years 2 weeks ago #85234

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
If you upgrade to the latest 1.92+ version, you will see that the the unique() function was added a couple of months ago. And, if you upgrade, you'll be able to use the self variable.

So, the question validation equation would be:
sum(self.sq_2)==100 && unique(self.sq_1)

And the question validation tip would be:
{if(sum(self.sq_2)==100,'','Sum of the percentage fields must be equal to 100<br/>')}

If you want the subject to rank all of the entries, you would set the question to mandatory, and could then use the following question validation equation and tip, respectively:
if(count(self)==18,(sum(self.sq_2)==100 && unique(self.sq_1)),1)
{if(count(self.sq_2)<9 or sum(self.sq_2)==100,'',implode('','Sum of the percentage fields must be equal to 100.  The current total is ',sum(self.sq_2),'<br/>'))}
{if(count(self.sq_1)<9 or unique(self.sq_1),'','Please rank each option once<br/>')}
The administrator has disabled public write access.

Validating an Array (Texts) 8 months 2 weeks ago #102994

  • Dede1989
  • Dede1989's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Hello,

i want to implement the same functionality with one additional condition: I realized two questions. The first question determines all relevant answers for "question 2" by using a filter. The user now should be able to define percentages (SUM=100) just for the visible options. Is there any chance to implement this behavior?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.505 seconds
Donation Image