Welcome to the LimeSurvey Community Forum

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

Adding "Other:" option to array

  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
1 year 6 months ago #232525 by Mazi
Replied by Mazi on topic Adding "Other:" option to array

Do you have permissions to insert JavaScript?

 
An easier to use solution could be this plugin which doesn't require adding any custom JavaScript for having text fields at array questions:  survey-consulting.com/product/array-with...t-limesurvey-plugin/

It adds the fields like this:
 

You can also check the demo survey at  plugins.mysurveyhosting.com/index.php/362484?newtest=Y&lang=en .

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com

Please Log in to join the conversation.

More
6 months 1 week ago #251127 by KatMey99
Replied by KatMey99 on topic Adding "Other:" option to array
Dear Tony Partner team,

I have come across your code to add an other option to arrays which has been very helpful. However, it doesn't seem to work to add an other option to "Array by column" questions, when the other option should be among the answer options in the rows (see picture below for illustration). I would be grateful for your guidance on how to adjust the code for this question type.

(I am using version 3.28.56.)

Thank you!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago - 6 months 1 week ago #251128 by tpartner
Replied by tpartner on topic Adding "Other:" option to array
This script will move the "Other" input into the last row of an array-by-column question:

Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQuestion = $('#question{QID}');
    var nextQuestion = thisQuestion.nextAll('.text-short:eq(0)');
 
    // Hide the next question
    nextQuestion.hide();
 
    // Move the text inputs
    $('tr[id^="javatbd"]:last td.answertext', thisQuestion).append($('.answer-item', nextQuestion));
 
    // Clean-up styling
    $('td.answertext .answer-item', thisQuestion).css({
      'padding': 0
    });
    $('td.answertext .answer-item div', thisQuestion).css({
      'padding': 0
    });
 
  });
</script>

 

Sample survey attached: 

File Attachment:

File Name: limesurvey...8552.lss
File Size:27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 months 1 week ago by tpartner.
The following user(s) said Thank You: KatMey99

Please Log in to join the conversation.

More
6 months 1 week ago #251138 by KatMey99
Replied by KatMey99 on topic Adding "Other:" option to array
Thank you so much for the prompt reply, this is just what I was looking for!

Please Log in to join the conversation.

More
2 months 2 weeks ago #255673 by bellagambad
Replied by bellagambad on topic Adding "Other:" option to array
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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 2 weeks ago #255674 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
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.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 2 weeks ago #255676 by tpartner
Replied by tpartner on topic Adding "Other:" option to array

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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 2 weeks ago #255678 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
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
2 months 2 weeks ago #255716 by bellagambad
Replied by bellagambad on topic Adding "Other:" option to array
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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 2 weeks ago #255718 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
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
2 months 2 weeks ago #255720 by bellagambad
Replied by bellagambad on topic Adding "Other:" option to array
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.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 2 weeks ago #255730 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
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:69 KB


Joffm


 

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

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose