Testet with selfhosted LimeSurvey CE 6.6.6 and fruity_twentythree (in question by question mode)
==================
Hello everyone,
I would like to quickly share function to correct the progress bar. There is an annoying and unresolved bug (see:
bugs.limesurvey.org/bug_relationship_gra...361&graph=dependency
) in Limesurvey that calculates the progressbar on permanently hidden questions.
You can call this function in a document ready function of your custom.js. Then try to put all your hidden questions at the beginning and at the end of your survey to get the best result.
To make this function work, you first need to add this code to a twig file (e.g. footer.twig):
Code:
<div id='SurveyName' style='display:none' hidden=1>{{ aSurveyInfo.name }}</div>
<div id='QuestionNumber' style='display:none' hidden=1>{{ processString('{self.qseq}') }}</div>
<div id='NumberOfAllQuestions' style='display:none' hidden=1>{{ processString('{NUMBEROFQUESTIONS}') }}</div>
<div id='NumberOfVisibleQuestions' style='display:none' hidden=1>{{ aSurveyInfo.iTotalquestions }}</div>
Now just add functions to your custom.js and call them from a document ready function. You can also distinguish between different surveys by the survey name.
Code:
if ("{SURVEYNAME}" == "Survey 1" ) {
// All hidden questions at start
AdjustProgressBar();
}
if ("{SURVEYNAME}" == "Survey 2" ) {
// All hidden questions at end
AdjustProgressBar(, false);
}
if ("{SURVEYNAME}" == "Survey 3" ) {
// 5 of X hidden questions at start
AdjustProgressBar(5);
}
Code:
function AdjustProgressBar(NumberOffHiddenQuestions = 0, HiddenQuestionsAtStart = true) {
var ToolTipText = "";
var SurveyName = $('#SurveyName').text();
var QuestionNumber = $('#QuestionNumber').text();
var NumberOfAllQuestions = $('#NumberOfAllQuestions').text();
var NumberOfVisibleQuestions = $('#NumberOfVisibleQuestions').text();
// var NumberOffHiddenQuestions = NumberOfAllQuestions - NumberOfVisibleQuestions;
if (NumberOffHiddenQuestions == 0) {
NumberOffHiddenQuestions = NumberOfAllQuestions - NumberOfVisibleQuestions;
}
QuestionNumber++;
// Adjust QuestionNumber if hidden question are at the beginning of the survey
if (HiddenQuestionsAtStart) {
QuestionNumber = QuestionNumber - NumberOffHiddenQuestions;
if (QuestionNumber < 0) {
QuestionNumber = 0;
}
}
var progressValue = Math.round(QuestionNumber / NumberOfVisibleQuestions * 100);
$('.progress-bar').css({
'transition': 'width 0s ease 0s',
'width': progressValue+'%'
});
ToolTipText = "You have answered ".concat(progressValue, "% of the questions.");
// Replace tooltip-text
$('.ls-progress-container').attr('title', ToolTipText).tooltip('dispose').tooltip();
// Replace text of div
$('.ls-progress-container .visually-hidden').text(ToolTipText);
}
Cheers