dear surveyjs team,
i'm trying to solve the following objective with surveyjs and would consider to purchase a commercial license to achieve it:
- we have a small series of image picker questions.
- (side note: i don't seem to be able to insert text underneath the images, in the sense of a caption – i've inserted "text" under "choices" but the text doesn't show up neither in safari nor in chrome)
- depending on the user's choices, we would like to enable different endings for the user. for example, user1 enters question1{a}, question2{b}, question3{a} and then receives ending1, user2 enters question1{b}, question2{b}, question3{c} and then receives ending2. the idea behind this is that a user receives a kind of an assessment at the end.
- doing a full permutation with the 15 choices and using rules we have isn't feasible (using visibleIf, and there is no scoring system that i understand could be applied, or am i wrong? in the sense of e.g. (question1{a}=90) + (question2{b}=40) + (question3{a}=20) = Score=150 -> ending1.
- how could such a multiple ending scenario be achieved using surveyjs? and how do i solve the caption issue? my email is steffen.walz@diconium.com.
thank you for letting me know!
kind regards,
steffen
Hello Steffen,
You can implement the needed functionality by using two SurveyJS Library features:
"Custom Properties" and "Custom Function".
Here is the code:
//Add the score property into choices/rateValues Survey.Serializer.addProperty("itemvalue", "score:number"); /*The function get the list of question names. It should be rating/dropdown/radiogroup, if end-user select a value, then try to find the score in the selected choices/rateValues item and add it into resulted summary */ var sumSingleChoicesScores = function (params) { if(!params || !Array.isArray(params)) return 0; var sum = 0; debugger; for(var i = 0; i < params.length; i ++) { var q = this.survey.getQuestionByName(params[i]); if(!q || q.isEmpty() || (!q.rateValues && !q.choices)) continue; var choices = !!q.rateValues ? q.rateValues : q.choices; var selectedItem = Survey.ItemValue.getItemByValue(choices, q.value); var score = !!selectedItem ? selectedItem.score: null; if(!!score) sum+= score; } return sum; }; //Register the custom function Survey.FunctionFactory.Instance.register("sumSingleChoicesScores", sumSingleChoicesScores);
The use the function in any expression as:
sumSingleChoicesScores('question1', 'question2', ...)
Here is the example.
Thank you,
Andrew
SurveyJS Team
hi andrew,
this is amazing! sorry for my belated reply, i've only just now noticed the reply and had been away over the weekend. will implement!
thanks so much!
cheers,
spw
Hello Steffen,
You are very welcome!
Thank you,
Andrew
SurveyJS Team
hi andrew,
one more question: is it absolutely not possible to use the image picker type of question with the scoring code you'd provided? would there be a workaround?
thanks,
steffen
Hello Steffen,
What do you mean? It should work with the current code. Image picker question has property "choices" and it is a new type derived from "itemvalue". It means that code should work perfectly.
Thank you,
Andrew
SurveyJS Team
hi andrew,
i see! i had asked because in the code comments, it says that "rating/dropdown/radiogroup" only. one last question:
how can i add text to the image picker, so that it appears for the user underneath each image that can be chosen? i've inserted "text" under "choices" but the text doesn't show up neither in safari nor in chrome.
thank you for your support,
spw
Hello,
The image picker question also has the
choices
property thus the code above should work.I think you need to set the https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#showLabel property to true.
Thanks, Serge
SurveyJS Team
hi serge,
fantastic, it now all works, incl. labels are being shown, thanks so much!
cheers,
spw