Welcome to the LimeSurvey Community Forum

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

Array-Text or Array-Numbers - need only one mandatory item per row

  • tixeon
  • tixeon's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
4 months 2 weeks ago - 4 months 2 weeks ago #266344 by tixeon
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.6.1
Own server or LimeSurvey hosting: Limesurvey
Survey theme/template: Fruity
==================

I require an array type question with one number entry box and two checkboxes per row.
I have successfully built this by modifying the Array(text) question type using scripts and advice found on this forum.
It works wonderfully except for one problem - When the question is set to 'mandatory', If a check-box on that row is selected, it still requires the text-box to be populated. I have used JavaScript to disable the text-boxes in instances where a check-box is selected, but the 'mandatory' warning still pops-up for the disabled text-boxes (see attached screenshot and .lss file).

I was wondering if there might be a way solve the problem using the Array(Numbers>Checkbox Layout) question type - as this looks like it has a compatible mandatory rule of <at least> one item per row. This would still require some JavaScript to create one number entry box and two checkboxes per row.

Otherwise is there an alternative way of resolving this (and without upsetting the question validation I already have in place)?

 
Last edit: 4 months 2 weeks ago by tixeon. Reason: More detail for clarification & ease of understanding

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 1 week ago #266379 by Joffm
Hi,
obviously the question can't be mandatory, which would force you to fill each cell.

But as the cells of one row are exclusive, it is sufficient to validate that the count of each row is greater than 0.
Like
count(self.sq_Y001)>0 and count(self.sq_Y002)>0 and ...

Joffm 
​​​​​​

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • tixeon
  • tixeon's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
4 months 1 week ago #266404 by tixeon
Thank you Joffm,

This solves the problem for Q1, unfortunately I am now encountering a related problem with a follow-up question (Q2).
Q2 is the same type of question and so requires the same validation, however it has an array filter so sub-questions only appear based on how Q1 is answered (using sub-question relevance equations).

It seems the Q2 validation is trying to validate the filtered-out (hidden) sub-questions.

I have tried to resolve this by using the following validation expression for Q2:

((Q1_SQ1_A1 ==0) OR (Q1_SQ1_A2 == 'Y') OR (Q1_SQ1_A3 == 'Y') OR (count(Q2_SQ1_A1,Q2_SQ1_A2,Q2_SQ1_A3)>0)) AND
((Q1_SQ2_A1 ==0) OR (Q1_SQ2_A2 == 'Y') OR (Q1_SQ2_A3 == 'Y') OR (count(Q2_SQ2_A1,Q2_SQ2_A2,Q2_SQ2_A3)>0)) AND
((Q1_SQ3_A1 ==0) OR (Q1_SQ3_A2 == 'Y') OR (Q1_SQ3_A3 == 'Y') OR (count(Q2_SQ3_A1,Q2_SQ3_A2,Q2_SQ3_A3)>0))

... It does not seem to be acknowledging any of these parts: (Q1_SQx_A1 ==0) OR (Q1_SQx_A2 == 'Y') OR (Q1_SQx_A3 == 'Y')

I have tried altering this expression in many ways and can't seem to get it working correctly, hopefully I have just made a minor error somewhere.
Please find new .lss file and screenshot attached.

 

Please Log in to join the conversation.

  • tixeon
  • tixeon's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
4 months 4 days ago - 4 months 4 days ago #266461 by tixeon
I have now solved this by altering a few things:
  • first adding .NAOK to each Qcode Variable, then:
  • swapping the validation expressions in the question validation field and sub-question validation field.
Doing this swap caused the validation to run on screen-load (prior to the respondent even attempting to answer the question) so to remedy this new problem I had to:
  • Delete the sub-question validation tip, and:
  • Create an if statement in the question text to display a "Please answer all rows" message when the sub-question validation is not met.

I have attached an .lss file for anyone why may come across a similar problem in the future and require a workaround.


This can now be closed.
Last edit: 4 months 4 days ago by tixeon. Reason: Add close message.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose