Can you use your library to create and then automatically grade a test? The user would have to indicate the right answers to questions somehow.
How to show that the answer is correct?
created 3 years ago
(modified 3 years ago)
Show previous comments
(0)
Comments
(0)
Sign in to comment on this post
Answers approved by surveyjs Support
Hello Alan,
You can use two events onValueChanged to make a question read-only and modify the title and "onTextMarkdown" to add css rules to your indicators.
Here is the code and working example:
JavaScriptsurvey.onValueChanged.add((sender, options) => {
const q = options.question;
if(!q) return;
q.readOnly = true;
q.title += q.isAnswerCorrect() ? "*Correct*" : "*Incorrect*";
});
survey.onTextMarkdown.add((sender, options) => {
debugger;
if(options.name !== "title" || !options.text) return;
if(options.text.indexOf("*Correct*") > -1) {
options.html = options.text.replace("*Correct*", "<span class='answer-correct'>Correct</span>");
}
if(options.text.indexOf("*Incorrect*") > -1) {
options.html = options.text.replace("*Incorrect*", "<span class='answer-incorrect'>Incorrect</span>");
}
});
Comments
(2)
AG
3 years ago
Ok, but how would the user designing the survey provide the correct answer to begin with? We need to know what the correct answer for each question is before we can grade the test.
AT
3 years ago
Hello Alan,
You can see in my example, there is "correctAnswer" property. You can find this property in the "Data" category.
Thank you,
Andrew
SurveyJS Team