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:
parent
caef206d51
commit
419034255a
1 changed files with 30 additions and 21 deletions
|
|
@ -621,36 +621,45 @@
|
||||||
|
|
||||||
function renderQuestionPrompt(p) {
|
function renderQuestionPrompt(p) {
|
||||||
const json = p.json;
|
const json = p.json;
|
||||||
const header = json.header || '';
|
const questions = json.questions || [];
|
||||||
const question = json.question || p.text;
|
|
||||||
const options = json.options || [];
|
|
||||||
const multiSelect = json.multi_select || false;
|
|
||||||
const allowsOther = json.allows_other || false;
|
|
||||||
const inputType = multiSelect ? 'checkbox' : 'radio';
|
|
||||||
|
|
||||||
const optionsHtml = options.map((opt, idx) => `
|
const questionsHtml = questions.map((q, qIdx) => {
|
||||||
<label class="prompt-option" onclick="selectOption('${p.id}', ${idx})">
|
const header = q.header || '';
|
||||||
<input type="${inputType}" name="prompt-${p.id}" value="${escapeHtml(opt)}">
|
const question = q.question || '';
|
||||||
<span class="prompt-option-label">${escapeHtml(opt)}</span>
|
const options = q.options || [];
|
||||||
</label>
|
const multiSelect = q.multi_select || false;
|
||||||
`).join('');
|
const allowsOther = q.allows_other || false;
|
||||||
|
const inputType = multiSelect ? 'checkbox' : 'radio';
|
||||||
|
const inputName = `prompt-${p.id}-${qIdx}`;
|
||||||
|
|
||||||
const otherHtml = allowsOther ? `
|
const optionsHtml = options.map((opt, idx) => `
|
||||||
<label class="prompt-option">
|
<label class="prompt-option" onclick="selectOption('${p.id}', ${idx})">
|
||||||
<input type="${inputType}" name="prompt-${p.id}" value="__other__" onclick="enableOtherInput('${p.id}')">
|
<input type="${inputType}" name="${inputName}" value="${escapeHtml(opt.value)}">
|
||||||
<span class="prompt-option-label">Other</span>
|
<span class="prompt-option-label">${escapeHtml(opt.label)}</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" class="prompt-other-input" id="other-${p.id}" placeholder="Enter your answer..." disabled>
|
`).join('');
|
||||||
` : '';
|
|
||||||
|
|
||||||
return `
|
const otherHtml = allowsOther ? `
|
||||||
<div class="prompt" data-prompt="${p.id}">
|
<label class="prompt-option">
|
||||||
|
<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}-${qIdx}" placeholder="Enter your answer..." disabled>
|
||||||
|
` : '';
|
||||||
|
|
||||||
|
return `
|
||||||
${header ? `<div class="prompt-header">${escapeHtml(header)}</div>` : ''}
|
${header ? `<div class="prompt-header">${escapeHtml(header)}</div>` : ''}
|
||||||
<div class="prompt-question">${escapeHtml(question)}</div>
|
<div class="prompt-question">${escapeHtml(question)}</div>
|
||||||
<div class="prompt-options">
|
<div class="prompt-options">
|
||||||
${optionsHtml}
|
${optionsHtml}
|
||||||
${otherHtml}
|
${otherHtml}
|
||||||
</div>
|
</div>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="prompt" data-prompt="${p.id}">
|
||||||
|
${questionsHtml}
|
||||||
<div class="prompt-actions">
|
<div class="prompt-actions">
|
||||||
<button class="btn btn-submit" onclick="submitRichPrompt('${p.id}')">Submit</button>
|
<button class="btn btn-submit" onclick="submitRichPrompt('${p.id}')">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue