Fix some regressions where text questions were falsely identified as invalid.
This commit is contained in:
parent
52592defe6
commit
6d528775a8
30
src/main.js
30
src/main.js
@ -185,21 +185,22 @@ function parseLine(line) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// For multiple-choice, split lines into array
|
// Split choices into array
|
||||||
if (q.type == 'ChooseOne' || q.type == 'ChooseAny') {
|
// Choices for text questions are labels
|
||||||
if (els[2] || els[2] != '') {
|
// No choices (empty string) are okay for text questions
|
||||||
q.choices = els[2].split('<br>')
|
// Also filter out empty lines because some people can't use spreadsheets
|
||||||
|
if (els[2] || (q.type == 'Text' && els[2] == '')) {
|
||||||
|
q.choices = els[2].split('<br>').filter(el => el != "")
|
||||||
} else {
|
} else {
|
||||||
alert('"Choose" question but no choices given at question "'
|
alert('No choices given at question "'
|
||||||
+ q.question + '"')
|
+ q.question + '"')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If multiple answers are allowed, they are newline-separated
|
// If multiple answers are allowed, they are newline-separated
|
||||||
// Also filter out empty lines because some people can't use spreadsheets
|
// Also filter out empty lines because some people can't use spreadsheets
|
||||||
if (els[3] || els[3] != '') {
|
if (els[3] && els[3] != '') {
|
||||||
q.answers = els[3].split('<br>').filter(el => el != "");
|
q.answers = els[3].split('<br>').filter(el => el != "")
|
||||||
} else {
|
} else {
|
||||||
alert('No answers given at question "'
|
alert('No answers given at question "'
|
||||||
+ q.question + '"')
|
+ q.question + '"')
|
||||||
@ -232,12 +233,12 @@ function parseSpreadsheet() {
|
|||||||
* 6. Re-add outer tabs (<tab>a<specialchar>b<tab>)
|
* 6. Re-add outer tabs (<tab>a<specialchar>b<tab>)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var text = textEl.value.replace(/\t"([^"\n]|"")+\n([^"]|"")*"\t/g,
|
var text = textEl.value.replace(/\t"([^"\n]|"")+\n([^"]|"")*"/g,
|
||||||
m => m.replace(/\n/g, '⎊')
|
m => m.replace(/\n/g, '⎊')
|
||||||
.replace(/""/g, '"')
|
.replace(/""/g, '"')
|
||||||
.replace(/^\t"(.*)"\t$/, '$1')
|
.replace(/^\t"(.*)"$/, '$1')
|
||||||
.replace(/\t/g, ' ')
|
.replace(/\t/g, ' ')
|
||||||
.replace(/^(.*)$/g, '\t$1\t')
|
.replace(/^(.*)$/g, '\t$1')
|
||||||
)
|
)
|
||||||
|
|
||||||
state.questions = text.split('\n').map(parseLine)
|
state.questions = text.split('\n').map(parseLine)
|
||||||
@ -280,10 +281,11 @@ function renderQuiz() {
|
|||||||
? `<label><input type="radio" name="q${i}" value="${ci+1}"> <p>${c}</p></label><br>`
|
? `<label><input type="radio" name="q${i}" value="${ci+1}"> <p>${c}</p></label><br>`
|
||||||
: `<label><input type="checkbox" name="q${i}" value="${ci+1}"> <p>${c}</p></label><br>`
|
: `<label><input type="checkbox" name="q${i}" value="${ci+1}"> <p>${c}</p></label><br>`
|
||||||
|
|
||||||
} else {
|
} else if (q.type == 'Text') {
|
||||||
|
|
||||||
for (c of q.choices)
|
// If choices were given, use them as labels, otherwise use generic label
|
||||||
html += `<label>${c}<input type="text" name="q${i}"></label>`
|
for ([ai, a] of q.answers.entries())
|
||||||
|
html += `<label>${q.choices[ai] ? q.choices[ai] : 'Answer'}<input type="text" name="q${i}"></label>`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user