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.
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.
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());
}
});
});
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.
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.