Welcome to the LimeSurvey Community Forum

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

Adding "Other:" option to array

More
1 year 10 months ago #251138 by KatMey99
Thank you so much for the prompt reply, this is just what I was looking for!

Please Log in to join the conversation.

More
1 year 6 months ago #255673 by bellagambad
Hi tpartner,
Thanks again for your solutions. I came across this topic, which helped me a lot. Is there a way to modify your code so that we have a button to add more "other" lines ? Or add a "other" line if the previous one is completed ?
I am using LS community edition 5.4.x
Thank you in advance !
Best regards,
David

Please Log in to join the conversation.

More
1 year 6 months ago #255674 by Joffm
1.More other lines?
Add more "short text" questions

2. Button?
Something similöar.
Search the forum for "varLengthArray"

3. Show if the previous is completed?
Use subquestion relevance to display the row if the previous is "not empty"

Joffm

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

Please Log in to join the conversation.

More
1 year 6 months ago #255676 by tpartner

Hi tpartner,
Thanks again for your solutions. I came across this topic, which helped me a lot. Is there a way to modify your code so that we have a button to add more "other" lines ? Or add a "other" line if the previous one is completed ?
I am using LS community edition 5.4.x
Thank you in advance !
Best regards,
David
I'm not sure why you would want to hide/show rows in an array-by-column question. Shouldn't the answers always be shown?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
1 year 6 months ago #255678 by Joffm
Oh, sorry,
I didn't realise that it was about an array by column.
Probably because I couldn't imagine it.
 

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

Please Log in to join the conversation.

More
1 year 6 months ago #255716 by bellagambad
thank you for your answers. In fact, I'm going to ask some nurses about setting up podiatry services for their patients. For each of their patients, they will have to specify whether certain criteria are met and whether a podiatry service is already in place. Each line represents a patient, and conditions will ensure that the nurses can only see the rows for their patients (and not the others). As the list of patients may not be exhaustive, I'd like to allow nurses to add to it as needed, hence the need for an indeterminate number of other options. I hope it makes sense !

Please Log in to join the conversation.

More
1 year 6 months ago #255718 by Joffm
And you are really sure, you use an array by column?

In my opinion this is a scenario for an array(numbers).

Please show what you want to achieve?
Screenshots or better, lss export of this/these relevant question(s)

Joffm

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

Please Log in to join the conversation.

More
1 year 6 months ago #255720 by bellagambad
Oops sorry ! yes absolutely, it's an array (numbers) with checkboxes. The third column is enabled if the second column's box is checked (thanks to you and tpartner again!). The questionnaire includes some (fictive) customer numbers. Let's say I am nurse X, I should only see the first two patients, nurse Y the next two patients and so on. Each nurse can add a patient if the latter is not is the list we provide in the questionnaire.

Please Log in to join the conversation.

More
1 year 6 months ago #255730 by Joffm
You only have to add more "short text" questions, the resp. subquestions

and adapt the script
Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
    var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)');
    var nextQuestion3 = $(thisQuestion).nextAll('.text-short:eq(2)');
    var nextQuestion4 = $(thisQuestion).nextAll('.text-short:eq(3)');
    var nextQuestions = $(nextQuestion1).add(nextQuestion2).add(nextQuestion3).add(nextQuestion4);
 
    var nextLength = nextQuestions.length;
    var sqLength = ('tr.answers-list', thisQuestion).length;
 
    // Hide the short-text questions
    $(nextQuestions).hide();
 
    // Move the hidden text inputs into the array
    for (i = 0; i < nextLength; i++) {
        var workingIndex = (sqLength - 1) - (nextLength - i);
        var nextQ = nextQuestions[i];
        $('th.answertext:eq('+workingIndex+')', thisQuestion).append($('input[type="text"]', nextQ)).closest('tr').addClass('otherRow');
    }    
 
    // Clean-up styling
    $('th.answertext .answer-item', thisQuestion).css({
      'padding': 0
    });
    $('th.answertext .answer-item div', thisQuestion).css({
      'padding': 0
    });
 
  });
</script>


Here
    var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
    var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)');
    var nextQuestion3 = $(thisQuestion).nextAll('.text-short:eq(2)');
    var nextQuestion4 = $(thisQuestion).nextAll('.text-short:eq(3)');
    var nextQuestions = $(nextQuestion1).add(nextQuestion2).add(nextQuestion3).add(nextQuestion4);


you collect all text questions and later you insert them in a loop.

And your request to add a new row if the previous is filled?
When is it filled?
You see it is a multiple question. LimeSurvey can't decide. The respondent may select one column or two.
Of course you can open a nerw row if the number of the client is entered and at least one column is selected.

If you use a better coding than SQ00x for both axis, like
y-axis: Y001, Y002,...
x-axis: X001, X002,...

you may use,
!is_empty(G01Q02) and count(self.sq_Y006_X)>0
!is_empty(G01Q0§) and count(self.sq_Y00/_X)>0
...

   



 

File Attachment:

File Name: limesurvey...1211.lss
File Size:68.81 KB


Joffm


 

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

Please Log in to join the conversation.

More
1 year 6 months ago #255743 by bellagambad
Thank you very much Joffm this is fantastic !
You're right, by filled I meant that a new patient id was reported. Checking a box in 1st or 2nd column is not necessary.
I imported your .lss and it works fine until the loop, so I have a total of 4 "other" options. I am not sure I understood your point concerning the coding of the axis, is it necessary to implement the loop ? Or is it just a best-practice ?
Thank you !
David

Please Log in to join the conversation.

More
1 year 6 months ago - 1 year 6 months ago #255748 by Joffm

Checking a box in 1st or 2nd column is not necessary.

Fine, adapt the subquestion relevance.

and it works fine until the loop

As the loop is part of the script it works or it does not.
What is your problem?

is it necessary to implement the loop

If you compare the two scripts you will see
  • in the first script there is only one "other" inserted and there is only one line to do this.
  • in the second script there you insert several "others" . Without a loop you have to insert one by one and always have to adapt the script if the number of "others" changes With the loop you are independent of this number.
It is like writing 100 times. You can do it like this
"This is row 1"
"This is row 2"
"This is row 3"
...
"This is row 99"
"This is row 100"
​​​​​​​ 
But you can use a loop like
for (x==1; x<101;x++) {
  write("This is row ".x);
}

I am not sure I understood your point concerning the coding of the axis

As you see in the subquestion relevance I used the variable "self"
Read the manual about these variables!
[url] www.limesurvey.org/manual/ExpressionScri....22that.22_variables [/url]
Meaning: with an "intelligent" coding you can shorten many equation.
In this case you'd have to write
count(G01Q03_SQ006_SQ001,G01Q03_SQ006_SQ002,G01Q03_SQ006_SQ003) 
with "better" coding
count(self.sq_Y006_X)

Further questions?
Send the lss export.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 6 months ago by Joffm.

Please Log in to join the conversation.

More
1 year 6 months ago #255769 by bellagambad
Thank you for your detailed answer Joffm. Sorry for the confusion, I thought there was a loop that made the number of "other" options infinite. Your explanation and a deeper look in the script you provided helped me understand what was the loop you were talking about in your previous post. Thank you for the manual reference, I'll need to learn that indeed.
Best regards,
David

Please Log in to join the conversation.

More
1 year 6 months ago #255789 by holch

I thought there was a loop that made the number of "other" options infinite.


There is no loop feature in Limesurvey.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

More
1 year 6 months ago #255795 by bellagambad
Ok, thank you for the clarification holch !
@Joffm : as I mentioned in a previous post, checking a box in 1st or 2nd column is not necessary. So I adapted the sq relevance like that : 
before the modification : !is_empty(G01Q02) and count(self.sq_SQ006_X)>=0
now : !is_empty(G01Q02) and I did the same for the following sub-questions.
Something seems to be wrong, as I only have the first "other" option showing and the following are not showing even if I complete the first short thext question. Any idea ? Please find the .lss attached if necessary.
Thank you in advance,
David
 

Please Log in to join the conversation.

More
1 year 6 months ago #255812 by Joffm
You can't remove this
and count(self.sq_SQ006_X)>=0

if it is possible to leave all checkboxes empty, add an option "None of these"
 

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

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose