Welcome to the LimeSurvey Community Forum

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

Questions appear in question group preview as wanted but not in survey preview

  • sarahschu
  • sarahschu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago - 3 years 4 months ago #216117 by sarahschu
Hello,

Unfortunately, some of the questions in my survey do not appear in the survey preview as I want them to be (and also not in the activated survey - I tried).
But it works in the question group preview. So I do not want to give up hope right now.

In the question group at stake I used two different workarounds (in two different questions) that I got from the manual and this forum:

- this workaround for one of the questions excluding all other options when ticking the last option in an array row (numbers with checkboxes) (using the latter script - for version 3.x): [url] manual.limesurvey.org/Workarounds:_Manip...ime_using_Javascript [/url]

- this workaround for another question further down: [url] forums.limesurvey.org/forum/can-i-do-thi...n-basic-array#166909 [/url]

I also used the latter workaround in another question group. There it works just fine (in the survey preview and when activated).

As I said, it seems to work when I look at the question group preview. But not in the survey preview etc.

Is there someone who could help me with this?

I am pretty sure, I am using a 3.xx Limesurvey version. Limesurvey is provided via a platform hosted by my university and I do not have administration rights to look it up, change templates etc.

Thanks a lot in advance!

Sarah
 
Last edit: 3 years 4 months ago by sarahschu. Reason: half my text got mixed up/deleted

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #216118 by Joffm
Hi,
yes, we see something.
Obviously you want to insert an exclusive column.
But what about the text box in the atray? What is the issure? Seems to work.

So you really should send the lss export of your survey.

Joffm

And at the moment I am a bit tired to communicate to Germans here with the danger of a language gap.

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

Please Log in to join the conversation.

More
3 years 4 months ago #216119 by jelo
I recommend to create a copy of the survey, remove the irrelevant questions and attach a LSS-Export here. That way you might get feedback about why the workaround is not working. The screenshots alone are seldom enough.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: sarahschu

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #216122 by Joffm
But I do not see an issue.
I used the same workarounds you mentioned.

 

File Attachment:

File Name: limesurvey...3863.lss
File Size:29 KB


Joffm




 

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

Please Log in to join the conversation.

  • sarahschu
  • sarahschu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #216125 by sarahschu
Thanks for your quick replies.

Here is my lss export stripped of all irrelevant questions

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #216126 by Joffm
Sorry,
In my opinion everything is fine.




You see I changed the "Other field in the first array; maybe better.

Joffm

So, please explain, where you see issues.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: sarahschu

Please Log in to join the conversation.

  • sarahschu
  • sarahschu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #216127 by sarahschu
Thanks a lot for your time and effort, Joffm! Yes, I see it works perfectly - as I want it to be!
Still it does not work, when I try. It´s still the same as I explained in the first post, not working when I take the survey preview - only when using the question group preview (sorry I cannot provide such a nice video so quickly ). So maybe it´s an issue with my browser (though I also already tried another one) - or something else on my laptop.

I will try pretest it with my colleagues now and see if they have issues aswell - sorry, I should have done that beforehand!

And would you provide your improved lss export here (moving the "other" field to another column in the array)? So far I haven´t figured out how to do that, though trying to follow other instructions.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #216131 by Joffm
Ok, morgen

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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #216162 by Joffm
Hi, Sarah,

(moving the "other" field to another column in the array)

Well, this is easy to understand.
You see these lines in the javascript
Code:
        // Move the text inputs
        $('tr.answers-list', thisQuestion).each(function(i) {
            var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
            $('td.answer-item:last input[type="radio"]', this).css({
                'position': 'absolute',
                'left': '-9999em'
            });
            $('td.answer-item:last', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
        });
Twice there is a 'td.answer-item:last'. So you can imagine here the column is defined (initially the last one)
 
But there are other "selectors" like ':first', ':odd', ...,  and ':eq(x)'
As ':last' selects the last element, ':first' selects the first element, ':eq(x)' selects the xth element (starting with 0)
Here an overview
[url] www.w3schools.com/jquery/jquery_ref_selectors.asp [/url]

Therefore you only have to change the lines above to
Code:
        // Move the text inputs
        $('tr.answers-list', thisQuestion).each(function(i) {
            var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
            $('td.answer-item:eq(3) input[type="radio"]', this).css({
                'position': 'absolute',
                'left': '-9999em'
            });
            $('td.answer-item:eq(3)', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
        });


Now something else.
1. Your first question
It is not very appealing to display all ten options right at the start.
a. You may display step by step, meaning, if one row is filled the next appears.
Thjis is easy to do by a subquestion relevance
'!is_empty(akteur_SQ001)' in the second subquestion
'!is_empty(akteur_SQ002)' in the third subquestion
...

b. There is a really nice way to display with buttons to add a new akteur.
 

 
Code:
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:complete',function() {
 
        // A function to add or remove rows of a multiple-short-text question
        function varLengthArray(qID) {
 
 
            // The HTML content of the Add/Remove elements - modify as you wish
            var addContent = '[+] Akteur hinzufügen';
            var removeContent = '[-] Akteur löschen';
 
            // Insert the buttons
            $('#question'+qID+' .subquestion-list').append('<div id="addButton'+qID+'" class="control-button btn btn-primary">'+addContent+'</div><div id="removeButton'+qID+'" class="control-button btn btn-danger">'+removeContent+'</div>');
 
            // Style the elements - you can modify here if you wish
            $('#question'+qID+' .control-button').css({
                'margin':'10px 0 10px 10px',
                'padding':'1px',
                'text-align':'center',
                'width':'auto',
                'cursor':'pointer',
                'float':'left'
            });
 
            // Initially hide the Remove element
            $( 'div#removeButton'+qID ).hide();
 
            // Call the functions below when clicked
            $( 'div#addButton'+qID ).click(function (event) {
                addRow(qID);
            });
            $( 'div#removeButton'+qID ).click(function (event) {
                removeRow(qID);
            });
 
            // Function to add a row, also shows the Remove element and hides the
            function addRow(qID) {
                $('#question'+qID+' .answer-item:hidden:first').show();
                $('div#removeButton'+qID).show();
                if ($('#question'+qID+' .answer-item:visible').length == $('#question'+qID+' .answer-item').length)  {
                    $('div#addButton'+qID).hide();
                }
            }
 
            // Function to remove a row and clear the input value
            function removeRow(qID) {
                $('#question'+qID+' .answer-item:visible:last').hide();
                $('#question'+qID+' .answer-item:hidden input[type="text"]').each(function(i) {
                    $(this).val('').trigger('keyup');
                });
                $( 'div#addButton'+qID ).show();
                if ($('#question'+qID+' .answer-item:visible').length == 1)  {
                    $('div#removeButton'+qID).hide();
                }
            }
 
            // Just some initialization stuff
            // Initially hide all except first row or any rows with populated inputs
            $('#question'+qID+' .answer-item input[type="text"]:not(:first)').each(function(i) {
                if($.trim($(this).val()) == '') {
                    $(this).closest('.answer-item').hide();
                }
                if ($('#question'+qID+' .answer-item:visible').length > 1)  {
        //            $('div#removeButton'+qID).show();
                }
            });
        }
 
        // Call the function with a question ID
        varLengthArray({QID});
    });
 
</script>

2. This question
 
a. You see there are different widths of the columns.
Done by these small snippets (javascript and css)
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
    // Add a question class
    thisQuestion.addClass('custom-array');
 
    // Column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i);
      });
    });
  });
</script>
Code:
<style type="text/css">.custom-array table.subquestion-list col {
    width: auto !important;
  }
 
  .custom-array table.subquestion-list thead .column-0 {  width: 22%; }
  .custom-array table.subquestion-list thead .column-1 {  width: 12%; }
  .custom-array table.subquestion-list thead .column-2 {  width: 12%; }
  .custom-array table.subquestion-list thead .column-3 {  width: 12%; }
  .custom-array table.subquestion-list thead .column-4 {  width: 30%; }
  .custom-array table.subquestion-list thead .column-5 {  width: 12%; }
</style>

b. In my opinion this is a multipunch question.
If you may select both 'Wohnraum' and 'Klima' (by clicking 'both') there is no reason that you couldn't select both 'Klima' and some 'other'.
But this is not possible because you use a normal array.

3. Frage 11.
If there was a contact anybody is able to answer this question about intensity.
Without contact you click the exclusive option "no contact".
No need to explain 'if no contact, please, leave empty'.

4. General you should consider to use '<wbr># instaed of your hard coded linefeeds which destroy the text on smaller devices

​​​​​​​
Now you got a lot of ideas.
Last but not least:
Here the sample survey
 

File Attachment:

File Name: limesurvey...9343.lss
File Size:73 KB


Joffm
 

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

Please Log in to join the conversation.

  • sarahschu
  • sarahschu's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago - 3 years 4 months ago #216266 by sarahschu
Thank you very, very much, Joffm, for all your help, suggestions & for explaining more in detail! I learned a lot.

Also I think you are right with your suggestion 2b, that it is rather a multipunch question. However I do not get a JS working with a numbers-array with checkboxes including „others“ to type in placed before the „no answer“ checkbox at the end (+ script which excludes all other answers when ticking the last option).

The suggestion by tpartner in this post ([url] forums.limesurvey.org/forum/can-i-do-thi...rray?start=15#167015 [/url]) does not work for me as I do not have administration rights/access to the template editor.

When implementing this JS directly in the question, it does not work:
Code:
<script type="text/javascript" charset="utf-8">
          $(document).on('ready pjax:scriptcomplete',function(){                              
                    // Identify the questions
                               var q1ID= {QID};
                               var thisQuestion = $('#question'+q1ID);
                               var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
                               var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
                     //Hide the multiple-short-text
                               nextQuestion.hide();
 
                     // Move the text inputs
                                 $('tr.subquestion-list', thisQuestion).each(function(i){
                                      var thisCode = $(this).attr('id').split('X'[2].split(q1ID)[1];
                                      $('td.answer-item:eq(3) input[type="checkbox"]', this).css({
                                           'position': 'absolute',
                                           'left': '-9999em'
                                       });
                                       $('td.answer-item:eq(3)', this).removeClass('checkbox-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
                               });
 
                        // Listeners on the text inputs
                                $('input[type="text"]', thisQuestion).on('keyup change', function(e){
                                        var thisCheckbox = $(this).closest('td').find('input[type="checkbox"]');
                                        if($.trim($(this).val()) != ''){
                                        $(thisCheckbox).prop('checked', true);
                                        $(thisCheckbox).prev('input:hidden').val(1);
                                        }
                                        else {
                                              $(thisCheckbox).prop('checked', false);
                                              $(thisCheckbox).prev('input:hidden').val('');
                                              }
                                              
                            // Fire Expression manager
                                         $(thisCheckbox).trigger('change');
                             });
                     });
</script>

And to close on my initial question:

The problem with non-working scripts persists (I tested with all my colleagues), if the questions are displayed in different question groups. If I place them in the the same question group, everything works as wanted.

So I guess it has something to do with the university template I am using or the university installation/platform in general – which I do not have access to change.
Last edit: 3 years 4 months ago by sarahschu. Reason: better reading

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #216269 by tpartner
All questions manipulated by JavaScript must be on the same page. JavaScript can only access what exists in the DOM when the script runs.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: sarahschu

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #216271 by Joffm
Hi, Sarah,
did you really place the array question and the short text question that has to be merged in two different groups?
Please, tell me that this wasn't true.

Each of my provided examples show that there is a "group by group" display and these two question are in one group.
And I think in each of the other examples showing this solution this is explained.

Joffm
 

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