[Ticket cloned from T8079: Set score for ranking type of questions]
Hi Andrew,
I discovered a very strange behavior of the survey from the last example you provided. Here is the updated example.
When ranking answers, if you move just 1mm up or down any of the answers and then release, just for them to have a position assigned (not changing their location among answers) at the end of the survey, the questions are repeated again although the answers are ranked.
I created a small video to show this.
Where could the issue be?
Thank you in advance.
Hello,
I believe it's a bug in the ranking question. We'll work on the fix and update this thread as soon as we'll have any results.
Thanks, Serge
SurveyJS Team
Hello,
this behavior is by design feature, not a bug. But maybe we could change it. For now, when you drag ranking item a little bit it changes the
indeterminate
state of question todeterminate
. So the question becomes answered with the default items order. And then yourareValuesEquals
returns true and the quiz restarted.Could you please describe your scenario in greater detail? Why do you need to restart the quiz when
areValuesEquals
function returnstrue
?as a workaround you could use custom
validator
for example:survey.onValidateQuestion.add(function(sender, options) { const q = options.question; const name = q.name; const value = q.value; const choices = q.visibleChoices; if (["Q1", "Q2", "Q3", "Q4"].indexOf(name) === -1) return; if(areValuesEquals(choices, value)) { options.error = "Please rank the items not in default order"; } });
but I am not sure that it is what you are trying to achieve
Thank you,
Dmitry
SurveyJS Team
Hi Dmitry,
Thank you for your reply.
The following functions were created with help from Andrew and their scope is to check if there are any left unanswered questions (user clicked next without ranking any answers) and to repeat those unanswered questions once at the end of the survey.
function areValuesEquals(choices, value) { if (!Array.isArray(value)) return false; // debugger; for (var i = 0; i < choices.length; i++) { if (choices[i].value !== value[i]) return false; } return true; } var surveyRunCount = 0; function rotate() { surveyRunCount++; if (surveyRunCount <= 1) { const questions = survey.getAllQuestions(); let hasQuestionsToShow = false; for (let i = 0; i < questions.length; i++) { const q = questions[i]; if (survey.firstPageIsStarted && q.page === survey.pages[0]) continue; //isEmpty() - was not touched if (!q.isEmpty() && !areValuesEquals(q.visibleChoices, q.value)) { q.visible = false; } else { hasQuestionsToShow = true; } } if (hasQuestionsToShow) { survey.clear(false, true); survey.start(); return true; } } return false; }
You're provided workaround is not suitable for my scenario, because:
maxTimeToFinishPage
was reached. The timer keeps running until the default order is changed.Please let me know if you need more info regarding this.
Thank you in advance,
Alex.
Hey,
If I understand correctly, you might don't need to run the
areValuesEquals
function at all. Checking!q.isEmpty ()
may be sufficient.If the user just skips the response,
q.isEmpty
will return true. But if the user drags the element a little without changing the order, the ranking question will set the state andq.isEmpty
will return true.In our opinion, this makes sense. In this case, we assume that the user is happy with the default order of items.
Thanks,
Dmitriy
SurveyJS Team
Hi Dmitriy,
Thank you very much for your time and effort into this.
Your proposed solution works great. You rock!
Best regards,
Alex.