Welcome to the LimeSurvey Community Forum

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

All in one but showing one by one - chatbot conversation survey style

  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162089 by SurveyDennis
All in one but showing one by one was created by SurveyDennis
I would like to show all questions on one page.
Setting the format to "All in one".

However I want to show all questions one by one, is this possible?

The reason I want to achieve this is because I would like to display all (answered) questions as well.

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago - 6 years 2 months ago #162092 by tpartner
Replied by tpartner on topic All in one but showing one by one
You could use JavaScript to hide all questions and then use the "submit" button to show them sequentially (but this may play havoc with any relevance you may have in place).

Something like this in template.js:

Code:
  $(document).ready(function(){  
 
    // Hide all but the first question
    $('.question-container').not(':eq(0)').hide();
 
    // Identify some elements 
    var nextButton = $('#movenextbtn, #movesubmitbtn');
    var firstQ = $('.question-container:first');
    var lastQ = $('.question-container:last');
 
    // Text for the submit button
    var nextText = 'Next';
    var submitText = 'Submit';
    $(nextButton).text(nextText);
 
    // Insert a Previous button
    var previousButton = $('<button type="button" class="button btn btn-lg  btn-default" style="display:none">Previous</button>').appendTo($(nextButton).closest('#navigator-container').find('.save-all.text-left'));
 
    // Listener on the submit button
    $(nextButton).on('click', function(e) {
      // Identify some elements
      var visibleQ = $('.question-container:visible');
      var nextQ = $(visibleQ).next('.question-container');
 
      // If there is a next question
      if(nextQ.length > 0) {
        // Prevent default action
        e.preventDefault();
 
        // Show the next question
        $(visibleQ).fadeOut(300, function(e) {
          $(nextQ).fadeIn(300, function(e) {
            if($(lastQ).is(':visible')) {
              $(nextButton).text(submitText);
            }
          });
        });
 
        // Handle the submit button text
        $('#navigator-container').fadeOut(300, function(e) {
          $(previousButton).show();
          if($(lastQ).is(':visible')) {
            $(nextButton).text(submitText);
          }
          $('#navigator-container').fadeIn(300, function(e) {
            $('#navigator-container button').prop('disabled', false).removeClass('disabled active');
          });
        });
      }
      // No next question so submit the page
      else {
        $(nextButton).removeClass('active');
      }
 
    });
 
    // Listener on the previous button
    $(previousButton).on('click', function(e) {
      // Identify some elements
      var visibleQ = $('.question-container:visible');
      var prevQ = $(visibleQ).prev('.question-container');
 
      e.preventDefault();
 
      // Show the previous question
      $(visibleQ).fadeOut(300, function(e) {
        $(prevQ).fadeIn(300);
      });
 
      // Handle the previous button visibility 
      $('#navigator-container').fadeOut(300, function(e) {
        if($(firstQ).is(':visible')) {
          $(previousButton).hide();
        }
        $('#navigator-container').fadeIn(300, function(e) {
          $('#navigator-container button').prop('disabled', false).removeClass('disabled active');
        });
      });
    });
  });

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 2 months ago by tpartner.
The following user(s) said Thank You: SurveyDennis
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago - 6 years 2 months ago #162097 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
Thanks Tony,

I am probably doing something wrong (when adding your script in the template.js from the default template).
But like always your code is very clear so I will see if I can manage this.

When I add the code with in the question itself the next question is hidden, and the next one appears on a following up screen.

Just as example: www.surveyfriendly.com/ls1/index.php/sur...94/newtest/Y/lang/en

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Last edit: 6 years 2 months ago by SurveyDennis.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #162098 by tpartner
Replied by tpartner on topic All in one but showing one by one
I see a JavaScript error in your survey.


Here is a working survey with the script in the source of Q1. Tested with the default template in version 2.73.0+171219.

File Attachment:

File Name: limesurvey...2-31.lss
File Size:25 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162099 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
Thanks again Tony,
I have uploaded your lss. I can see it working

www.surveyfriendly.com/ls1/index.php/sur...98/newtest/Y/lang/en

But just to be sure, the previous questions don't stay on the screen after answering them and moving to the next question.

I still have that error indeed in the default template.
Strange, I didn't changed that (LS Version 2.55.1+161026)

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago - 6 years 2 months ago #162101 by tpartner
Replied by tpartner on topic All in one but showing one by one
Yes, using that script, each question is hidden as the next one is shown.

If you want the currently visible questions to remain as the next ones are shown, use this script:

Code:
  $(document).ready(function(){  
 
    // Hide all but the first question
    $('.question-container').not(':eq(0)').hide();
 
    // Identify some elements 
    var nextButton = $('#movenextbtn, #movesubmitbtn');
    var firstQ = $('.question-container:first');
    var lastQ = $('.question-container:last');
 
    // Text for the submit button
    var nextText = 'Next';
    var submitText = 'Submit';
    $(nextButton).text(nextText);
 
    // Listener on the submit button
    $(nextButton).on('click', function(e) {
      // Identify some elements
      var visibleQ = $('.question-container:visible');
      var nextQ = $(visibleQ).next('.question-container');
 
      // If there is a next question
      if(nextQ.length > 0) {
        // Prevent default action
        e.preventDefault();
 
        // Show the next question
        $(nextQ).fadeIn(600, function(e) {
          if($(lastQ).is(':visible')) {
            $(nextButton).text(submitText);
          }
        });
 
        // Handle the submit button text and scrolling
        $(nextButton).fadeOut(150, function(e) {
          if($(lastQ).is(':visible')) {
            $(nextButton).text(submitText);
            $('html, body').animate({ 
              scrollTop: $(document).height() 
            }, 1000);
          }
          else {
            $('html, body').animate({
              scrollTop: $(nextQ).offset().top
            }, 1000);
          }
          $(nextButton).fadeIn(150, function(e) {
            $('#navigator-container button').prop('disabled', false).removeClass('disabled active');
          });
        });
      }
      // No next question so submit the page
      else {
        $(nextButton).removeClass('active');
        alert($(document).height());
      }
 
    });
  });

Sample survey attached:

File Attachment:

File Name: limesurvey...1-01.lss
File Size:24 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 2 months ago by tpartner.
The following user(s) said Thank You: SurveyDennis
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 2 months ago #162102 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
Like always - many thanks for this!! All working!!

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago - 4 years 9 months ago #185284 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
I am picking up this old topic again.


The example script is working as well in Version 3.17.4+190529
Only changed the movenextbtn to ls-button-submit.


I was just wondering if there is a workaround to set conditions - even that I have all questions in one group and the format is set to Group by Group.

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Last edit: 4 years 9 months ago by SurveyDennis.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185296 by tpartner
Replied by tpartner on topic All in one but showing one by one
Sorry, I don't understand the question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago #185300 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
I would like to use conditions for the questions in this group.
It is not working because the survey is set as group by group.

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago - 4 years 9 months ago #185343 by tpartner
Replied by tpartner on topic All in one but showing one by one
Well, in my first post I did say "but this may play havoc with any relevance you may have in place".

However, if the condition/relevance is imposed from a previous group, try changing this line:

Code:
var nextQ = $(visibleQ).next('.question-container');

To this:

Code:
var nextQ = $(visibleQ).nextAll('.question-container:not(.ls-irrelevant):eq(0)');

This should only show the questions sequentially that are not hidden via conditions/relevance.

I don't see any simple solution for questions that are hidden via conditions/relevance imposed within the same group.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 9 months ago by tpartner.
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago - 4 years 9 months ago #185344 by SurveyDennis
Replied by SurveyDennis on topic All in one but showing one by one
Like always many thanks for your reply and solution.
This works.

But just wondering one more thing. Not sure if this can be done:

I have 5 questions in the group (Q1,Q2,Q3,Q4,Q5)
If you answer option 1 in Q1 you get Q2
If you answer option 2 in Q1 you get Q3

For Q4 and Q5 and I don't have a filter anymore, but those are not shown anymore.


Would it help to see the demo?

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Last edit: 4 years 9 months ago by SurveyDennis.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose