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) {
|
||||
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 inputType = multiSelect ? 'checkbox' : 'radio';
|
||||
const questions = json.questions || [];
|
||||
|
||||
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>
|
||||
</label>
|
||||
`).join('');
|
||||
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 otherHtml = allowsOther ? `
|
||||
<label class="prompt-option">
|
||||
<input type="${inputType}" name="prompt-${p.id}" value="__other__" onclick="enableOtherInput('${p.id}')">
|
||||
<span class="prompt-option-label">Other</span>
|
||||
</label>
|
||||
<input type="text" class="prompt-other-input" id="other-${p.id}" placeholder="Enter your answer..." disabled>
|
||||
` : '';
|
||||
const optionsHtml = options.map((opt, idx) => `
|
||||
<label class="prompt-option" onclick="selectOption('${p.id}', ${idx})">
|
||||
<input type="${inputType}" name="${inputName}" value="${escapeHtml(opt.value)}">
|
||||
<span class="prompt-option-label">${escapeHtml(opt.label)}</span>
|
||||
</label>
|
||||
`).join('');
|
||||
|
||||
return `
|
||||
<div class="prompt" data-prompt="${p.id}">
|
||||
const otherHtml = allowsOther ? `
|
||||
<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>` : ''}
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue