Making multiple examps available
Updating dependencies Possibly fixing errors on MultipleSelect Questions
This commit is contained in:
@ -5,26 +5,16 @@
|
||||
export let showResult = false;
|
||||
export let isCorrect = false;
|
||||
|
||||
|
||||
$: options = randomize(Object.keys(question.options).map(e => ({ key: e, value: question.options[e] })));
|
||||
|
||||
let selected = [];
|
||||
|
||||
$: isCorrect = selected.length === question.correct.length && selected.every(val => question.correct.find(v => v === val));
|
||||
|
||||
$: console.log("Selected:", selected, "showResult:", showResult, "isCorrect", isCorrect);
|
||||
|
||||
|
||||
function toggle(id) {
|
||||
if (selected.indexOf(id) < 0) {
|
||||
selected = [...selected, id];
|
||||
} else {
|
||||
selected = selected.filter(e => e !== id);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<h3>Select {question.correct.length}</h3>
|
||||
{#each options as option}
|
||||
{#each options as option (option.key)}
|
||||
<div
|
||||
key={option.key}
|
||||
class:should={showResult && question.correct.indexOf(option.key) >= 0}
|
||||
@ -32,9 +22,10 @@
|
||||
<label class="input-checkbox" for={option.key}>{@html option.value.replace(/\n/g, "<br>")}
|
||||
<input
|
||||
type="checkbox"
|
||||
id={option.key}
|
||||
checked={selected.indexOf(option.key) >= 0}
|
||||
on:click={(evt)=>showResult ? evt.preventDefault() : toggle(option.key)}
|
||||
id={option.key}
|
||||
bind:group={selected}
|
||||
on:click={(evt)=>showResult ? evt.preventDefault() : undefined}
|
||||
value={option.key}
|
||||
>
|
||||
<span></span>
|
||||
</label>
|
||||
|
Reference in New Issue
Block a user