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

More
1 year 8 months ago #162089 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

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 year 8 months ago - 1 year 8 months ago #162092 by tpartner
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:

	$(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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 1 year 8 months ago by tpartner.
The following user(s) said Thank You: SurveyDennis

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago - 1 year 8 months ago #162097 by SurveyDennis
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: 1 year 8 months ago by SurveyDennis.

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago #162098 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago #162099 by SurveyDennis
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

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago - 1 year 8 months ago #162101 by tpartner
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:

	$(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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 1 year 8 months ago by tpartner.
The following user(s) said Thank You: SurveyDennis

Please Log in or Create an account to join the conversation.

More
1 year 8 months ago #162102 by SurveyDennis
Like always - many thanks for this!! All working!!

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago - 3 months 2 weeks ago #185284 by SurveyDennis
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: 3 months 2 weeks ago by SurveyDennis.

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago #185296 by tpartner
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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago #185300 by SurveyDennis
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

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago - 3 months 2 weeks ago #185343 by tpartner
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:

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

To this:

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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 3 months 2 weeks ago by tpartner.

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago - 3 months 2 weeks ago #185344 by SurveyDennis
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: 3 months 2 weeks ago by SurveyDennis.

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago - 3 months 2 weeks ago #185345 by tpartner
As I said "I don't see any simple solution for questions that are hidden via conditions/relevance imposed within the same group, but if you can attache a small sample survey I'll try to find time to look.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 3 months 2 weeks ago by tpartner.
The following user(s) said Thank You: SurveyDennis

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago #185347 by SurveyDennis
Thanks, see attached the lss.
The layout is also depended on a custom template but you see the idea.

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Attachments:

Please Log in or Create an account to join the conversation.

More
3 months 2 days ago #185813 by SurveyDennis
I have tried some more on this workaround.
However I can't get it working as I would love to. My main goal was to create a sort of a chatbot survey style.

Maybe it can be in any use as base code for anyone that is trying the same.

TODO: conditions and saving the data after the last submit.
Attached the .lss
And hereby a link to my example:
www.surveyfriendly.com/ls3/index.php/48787?newtest=Y&lang=en

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Attachments:

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!