Welcome to the LimeSurvey Community Forum

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

Inserting text boxes in an array by column question

  • Marjolijn25
  • Marjolijn25's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 6 days ago #271072 by Marjolijn25
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition  Version 5.4.8+221024
Own server or LimeSurvey hosting: Pretty sure it's own server
Survey theme/template: fruity
==================

I am setting up a questionnaire in which I have an array by column question of which the final row is an "other, namely:" option. I was able, with help by Copilot, to insert text boxes in this final row using the below script. My only issue now is that the text boxes are enables regardless of which radio button is selected, e.g. a participant could not check the "other, namely:" button but still write something in the text box (see picture attached). I've tried fixing this by asking Copilot to adjust the script for me, but it never seems to work and/or it introduces another problem. Can you help me?

This is my current script:

$(document).ready(function() {
    // Target the last row of the array question (Ethnic)
    var arrayRow = $('#question111152 .subquestion-list tr:last');

    // Loop through each input in the multiple short text question (G01Q02)
    $('#question111169 .answer-item input[type="text"]').each(function(index) {
        var input = $(this).detach(); // Detach input from original location
        input.css('width', '90%'); // Optional: style the input
        arrayRow.find('td:eq(' + index + ')').append(input); // Insert into corresponding column cell
    });

    // Hide the original multiple short text question
    $('#question111169').hide();
});
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 4 days ago - 3 weeks 4 days ago #271088 by Joffm
Hi,

with help by Copilot

AI programs related to LimeSurvey are always a source of hilarity and laughter.
Unfortunately, you have no real knowledge of LimeSurvey.

Well, "array by column" is seldom used and therefore there are no worling workarounds at hand.
But you can use:
1. An "array by column" and a following question of type "multiple short text" where the subquestions are displayed if the "Other" was selected.
Built-in, no script 

2.  An "array" with a following question of type "multiple short text" where the input fields are merged into the array by javascript

Of course the "Other" option is as exclusive as the buttons.
Here ther is additionally insered 
  • different column widths
  • left alignment of subquestion text
3. If there are more precoded countries you may think of an array(text) where in the first column there is a dropdown )with the countries)
and in the second column a text fild that is only enabled if the respondent selects "other" 
Example:
 
Third column is only enabled if in the second column is selected "Handball" or "Football"

If you have any preferece, please tell us.
As I am busy at the moment, I will then send a working sample.

Best redards
Joffm

Pretty sure it's own server

You'd be sure if you had rented your own webspace from a webhosting company.
So, this seems to be an anstallation of your company, your university, or what?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 weeks 4 days ago by Joffm.

Please Log in to join the conversation.

  • Marjolijn25
  • Marjolijn25's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 4 days ago #271093 by Marjolijn25
Replied by Marjolijn25 on topic Inserting text boxes in an array by column question
Hello Joffm,

Thank you for your response. I'm a total beginner at LimeSurvey as it's my first time using it. I'm used to working with Qualtrics, but the university I work at now only permits using LimeSurvey, so I need to learn how to use it!

At first, I set up a normal array question indeed, but as I have quite some pre-coded countries I want to insert, I found the array to become quite wide on the screen. So, I switched to an array by column question type, instead. Thank you for pointing out that that is an uncommonly used question type. 

The array(text) option you mention seems the most suitable. If you would be so kind to send an example, I would appreciate that very much. I'll get back to working on my survey after the weekend, so please don't feel rushed to respond quickly.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 2 days ago - 3 weeks 1 day ago #271100 by Joffm
Hi, Marjolijn,
here I send a sample with five options to display this question.

1. Without any scripting; only built-in features
 
2. Array with "Other" input field in each row.
 
3. Array(text) with dropdown and dependend input field
 
4. "Autocomplete", here you select from all countries in the world
 
5. Three "searchable dropdowns" side by side  (again you may enter all countries of the world; here only A-C implemented (I was too lazy))
 


and the lss
 

File Attachment:

File Name: limesurvey...6146.lss
File Size:174 KB


Joffm

And you can combine, e.g. the auto complete in Option 1 or 3.
The advantage: Always the same spelling of countries - easier to analise.
 
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 weeks 1 day ago by Joffm.

Please Log in to join the conversation.

  • Marjolijn25
  • Marjolijn25's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 13 hours ago #271111 by Marjolijn25
Replied by Marjolijn25 on topic Inserting text boxes in an array by column question
Hi Joffm,

Thank you so much for the elaborate answer - this is really enlightening! You've offered a more aesthetic and streamlined option for this question than I could've thought of myself.

When I import the .lss file and go into edit mode for e.g. question 4 (Q4), I don't see anything besides the subquestions (also not in the Script tab). Am I not looking at the right part? I am wondering how you implemented the auto complete into the multiple short texts type question.

Really appreciated - thanks!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 12 hours ago #271113 by Joffm
Hi,
I never use this "script" tab. There are some limitations that I don't like.

You find this script in the in source code of the question text 

Joffm

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

Please Log in to join the conversation.

  • Marjolijn25
  • Marjolijn25's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 weeks 5 days ago #271134 by Marjolijn25
Replied by Marjolijn25 on topic Inserting text boxes in an array by column question
Thank you for your super quick reply and I am sorry to continually bother you with this, but unfortunately, the source code appears to be empty for me.



I've imported the .lss into my online LimeSurvey account because my university has turned off imports into the university installation. Could you possibly share the code here for the autocomplete? Thank you so much! 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 weeks 5 days ago - 2 weeks 5 days ago #271135 by Joffm
Hi, Marjolijn,
did you make sure that you can enter javascript code?
Many universities do not allow this.

An easy test:
In a question enter this (in source code mode)
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
alert("Hello, javascript speaking");
});
</script>

If it pops up, fine. If not, bad luck and you have to go back to the solutions without javascript.

Another indicator is:
Enter the script,
"save & close"
"Edit" the question again.
Is the script still there?

Anyway: here is the script for Q4
Code:
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
 
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    var countries= ["Afghanistan", "Ägypten", "Albanien", "Algerien", "Andorra", "Angola", "Antigua und Barbuda", "Äquatorialguinea", "Argentinien", "Armenien", "Aserbaidschan", "Äthiopien", "Australien", "Bahamas", "Bahrain", "Bangladesch", "Barbados", "Belgien", "Belize", "Benin", "Bergkarabach", "Bhutan", "Bolivien", "Bosnien und Herzegowina", "Botswana", "Brasilien", "Brunei", "Bulgarien", "Burkina Faso", "Burundi", "Chile", "Volksrepublik China", "Cookinseln", "Costa Rica", "Dänemark", "Deutschland", "Dominica", "Dominikanische Republik", "Dschibuti", "Ecuador", "El Salvador", "Elfenbeinküste", "Eritrea", "Estland", "Fidschi", "Finnland", "Frankreich", "Gabun", "Gambia", "Georgien", "Ghana", "Grenada", "Griechenland", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Indien", "Indonesien", "Irak", "Iran", "Irland", "Island", "Israel", "Italien", "Jamaika", "Japan", "Jemen", "Jordanien", "Kambodscha", "Kamerun", "Kanada", "Kap Verde", "Kasachstan", "Katar", "Kenia", "Kirgisistan", "Kiribati", "Kolumbien", "Komoren", "Kongo, Demokratische Republik", "Kongo, Republik", "Korea, Nord", "Korea, Süd", "Kosovo", "Kuba", "Kuwait", "Laos", "Lesotho", "Lettland", "Libanon", "Liberia", "Libyen", "Liechtenstein", "Luxemburg", "Madagaskar", "Malawi", "Malaysia", "Malediven", "Mali", "Malta", "Marokko", "Marshallinseln", "Mauretanien", "Mauritius", "Mazedonien", "Mexiko", "Mikronesien", "Moldawien", "Monaco", "Mongolei", "Montenegro", "Mosambik", "Myanmar", "Namibia", "Nauru", "Nepal", "Neuseeland", "Nicaragua", "Königreich der Niederlande", "Niger", "Nigeria", "Niue", "Nordzypern", "Norwegen", "Oman", "Österreich", "Osttimor / Timor-Leste", "Pakistan", "Palästina", "Palau", "Panama", "Papua-Neuguinea", "Paraguay", "Peru", "Philippinen", "Polen", "Portugal", "Ruanda", "Rumänien", "Russland", "Salomonen", "Sambia", "Samoa", "San Marino", "São Tomé und Príncipe", "Saudi-Arabien", "Schweden", "Schweiz", "Senegal", "Serbien", "Seychellen", "Sierra Leone", "Simbabwe", "Singapur", "Slowakei", "Somalia", "Somaliland", "Spanien", "Sri Lanka", "St. Kitts und Nevis", "St. Lucia", "St. Vincent und die Grenadinen", "Südafrika", "Sudan", "Südossetien", "Südsudan", "Surinam", "Swasiland", "Syrien", "Tadschikistan", "Taiwan", "Tansania", "Thailand", "Togo", "Tonga", "Transnistrien", "Trinidad und Tobago", "Tschad", "Tschechien", "Tunesien", "Türkei", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "Ungarn", "Uruguay", "Usbekistan", "Vanuatu", "Vatikanstadt", "Venezuela", "Vereinigte Arabische Emirate", "Vereinigte Staaten", "Vereinigtes Königreich", "Vietnam", "Weißrussland", "Westsahara", "Zentralafrikanische Republik", "Zypern"];
    
    $('#question{QID} input[type="text"]:eq(0)').autocomplete({
      minLength: 2,
      source: countries,
    });
 
    $('#question{QID} input[type="text"]:eq(1)').autocomplete({
      minLength: 2,
      source: countries,
    });
 
    $('#question{QID} input[type="text"]:eq(2)').autocomplete({
      minLength: 2,
      source: countries,
    });
 
 
  });
</script>
 
<style type="text/css">label.control-label {
    text-align: left !important;
}
</style>


At the end you see a css snippet to left align the subquestion text

In the first two lines two necessary libraries are loaded from a CDN.
It is recommended to upload these files to your own installation.
Here a zip file containing the three files (jquery-csv is not necessary for this approach)
 

File Attachment:

File Name: jquery_Bib...eken.zip
File Size:77 KB


Unzip and upload them to the files folder ("Ressources")
 
Then you use the wizard (as if enter an HTML5 video)
 
and select one of the files.
This is only to get known of the path you have to enter in the script
 
You must not proceed, just close the wizard.

This means you change the path in the script abpve to the one displayed (with the correct filename)
So here you'd exchange
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
<script src=" code.jquery.com/ui/1.12.1/jquery-ui.js ">

to
<link href="/lime6/upload/surveys/{SID}/files/jquery-ui.min.css" rel="stylesheet" />
<script src="/lime6/upload/surveys/{SID}/files/jquery-ui.min.js"></script>

Here I use the variable {SID} to get the correct surveyID in case the surey is copied, exported, imported, or so.

And here the country names are mostly in German.
And you should to revise it depending on your question.
If you want to know more or less the nationality "Koninkrijk der Nederlanden" is sufficient.
But if you want to know the region, you have to distinguish between
1. Netherlands (incl. BES-eilanden, Bonaire, St. Eustatius, Saba)
2. Aruba
3. Curaco
4. Sint Maarten

I suppose your goal is the second. You already entered "Netherlands", "Aruba" and "Curacao" separately.
This is only an example, because there are other countries with this issue (France with Martinique, Guadeloupe, Guayana, Mayotte, Reunion)

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 weeks 5 days ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose