Skip to content

Commit 43f205c

Browse files
committed
JS to handle multiple sample answer evaluation
1 parent 805bce9 commit 43f205c

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

amd/build/responserun.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/responserun.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/responserun.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,42 @@ import Notify from 'core/notification';
2727
import Log from 'core/log';
2828
import {exception as displayException} from 'core/notification';
2929

30-
const Selectors = {
31-
fields: {
32-
sampleanswer: '#id_sampleanswer',
33-
sampleanswerbtn: '#id_sampleanswerbtn',
34-
sampleanswereval: '#id_sampleanswereval',
35-
spinner: '#id_spinner',
36-
aiprompt: '#id_aiprompt',
37-
markscheme: '#id_markscheme',
38-
defaultmark: '#id_defaultmark',
39-
},
40-
};
4130

4231
export const init = (contextid) => {
4332

33+
const Selectors = {
34+
fields: {
35+
sampleanswer: '#id_sampleanswer',
36+
sampleanswerbtn: '#id_sampleanswerbtn',
37+
sampleanswereval: '#id_sampleanswereval',
38+
},
39+
};
40+
let elementcount = document.querySelectorAll("[id^='id_sampleanswerbtn']");
41+
let SelectorsWithCount = {};
42+
43+
for (let i = 0; i < elementcount.length; i++) {
44+
SelectorsWithCount.fields = {};
45+
for (let key in Selectors.fields) {
46+
SelectorsWithCount.fields[key] = Selectors.fields[key] + "_" + i;
47+
SelectorsWithCount.fields.aiprompt = '#id_aiprompt';
48+
SelectorsWithCount.fields.markscheme = '#id_markscheme';
49+
SelectorsWithCount.fields.defaultmark = '#id_defaultmark';
50+
SelectorsWithCount.fields.spinner = '#id_spinner';
51+
}
52+
clickSetup(contextid, SelectorsWithCount);
53+
}
54+
55+
};
56+
57+
/**
58+
* Configure event handlers
59+
*
60+
* @param {number} contextid
61+
* @param {object} Selectors
62+
*/
63+
function clickSetup(contextid, Selectors) {
4464
// Set up strings
45-
var strings={};
65+
var strings = {};
4666
get_strings([
4767
{"key": "prompttester", "component": 'qtype_aitext'},
4868
{"key": "sampleanswerempty", "component": 'qtype_aitext'},
@@ -96,4 +116,4 @@ export const init = (contextid) => {
96116

97117
}); // End of click.
98118

99-
};
119+
}

0 commit comments

Comments
 (0)