Fix QuestionPrompt to iterate questions array

QuestionPrompt has a questions array, not flat fields. Updated rendering
to iterate over each question item with its own header, question text,
and options.
This commit is contained in:
Jared Miller 2026-01-28 13:02:45 -05:00
parent caef206d51
commit 419034255a
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -621,36 +621,45 @@
function renderQuestionPrompt(p) {
const json = p.json;
const header = json.header || '';
const question = json.question || p.text;
const options = json.options || [];
const multiSelect = json.multi_select || false;
const allowsOther = json.allows_other || false;
const questions = json.questions || [];
const questionsHtml = questions.map((q, qIdx) => {
const header = q.header || '';
const question = q.question || '';
const options = q.options || [];
const multiSelect = q.multi_select || false;
const allowsOther = q.allows_other || false;
const inputType = multiSelect ? 'checkbox' : 'radio';
const inputName = `prompt-${p.id}-${qIdx}`;
const optionsHtml = options.map((opt, idx) => `
<label class="prompt-option" onclick="selectOption('${p.id}', ${idx})">
<input type="${inputType}" name="prompt-${p.id}" value="${escapeHtml(opt)}">
<span class="prompt-option-label">${escapeHtml(opt)}</span>
<input type="${inputType}" name="${inputName}" value="${escapeHtml(opt.value)}">
<span class="prompt-option-label">${escapeHtml(opt.label)}</span>
</label>
`).join('');
const otherHtml = allowsOther ? `
<label class="prompt-option">
<input type="${inputType}" name="prompt-${p.id}" value="__other__" onclick="enableOtherInput('${p.id}')">
<input type="${inputType}" name="${inputName}" value="__other__" onclick="enableOtherInput('${p.id}-${qIdx}')">
<span class="prompt-option-label">Other</span>
</label>
<input type="text" class="prompt-other-input" id="other-${p.id}" placeholder="Enter your answer..." disabled>
<input type="text" class="prompt-other-input" id="other-${p.id}-${qIdx}" placeholder="Enter your answer..." disabled>
` : '';
return `
<div class="prompt" data-prompt="${p.id}">
${header ? `<div class="prompt-header">${escapeHtml(header)}</div>` : ''}
<div class="prompt-question">${escapeHtml(question)}</div>
<div class="prompt-options">
${optionsHtml}
${otherHtml}
</div>
`;
}).join('');
return `
<div class="prompt" data-prompt="${p.id}">
${questionsHtml}
<div class="prompt-actions">
<button class="btn btn-submit" onclick="submitRichPrompt('${p.id}')">Submit</button>
</div>