ui: objective: support multi-line answer

pull/565/head
undefined 1 year ago
parent a0b2e65319
commit d55cf5ae45
No known key found for this signature in database

@ -187,7 +187,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
$('.outer-loader-container').show(); $('.outer-loader-container').show();
const ans = {}; const ans = {};
let cnt = 0; let cnt = 0;
const reg = /{{ (input|select|multiselect)\(\d+(-\d+)?\) }}/g; const reg = /{{ (input|select|multiselect|textarea)\(\d+(-\d+)?\) }}/g;
$('.problem-content .typo').children().each((i, e) => { $('.problem-content .typo').children().each((i, e) => {
if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return; if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return;
const questions = []; const questions = [];
@ -195,13 +195,19 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
while (q = reg.exec(e.innerText)) questions.push(q); // eslint-disable-line no-cond-assign while (q = reg.exec(e.innerText)) questions.push(q); // eslint-disable-line no-cond-assign
for (const [info, type] of questions) { for (const [info, type] of questions) {
cnt++; cnt++;
const id = info.replace(/{{ (input|select|multiselect)\((\d+(-\d+)?)\) }}/, '$2'); const id = info.replace(/{{ (input|select|multiselect|textarea)\((\d+(-\d+)?)\) }}/, '$2');
if (type === 'input') { if (type === 'input') {
$(e).html($(e).html().replace(info, tpl` $(e).html($(e).html().replace(info, tpl`
<div class="objective_${id} medium-3" style="display: inline-block;"> <div class="objective_${id} medium-3" style="display: inline-block;">
<input type="text" name="${id}" class="textbox objective-input"> <input type="text" name="${id}" class="textbox objective-input">
</div> </div>
`)); `));
} else if (type === 'textarea') {
$(e).html($(e).html().replace(info, tpl`
<div class="objective_${id} medium-6">
<textarea name="${id}" class="textbox objective-input"></textarea>
</div>
`));
} else { } else {
if ($(e).next()[0]?.tagName !== 'UL') { if ($(e).next()[0]?.tagName !== 'UL') {
cnt--; cnt--;
@ -224,7 +230,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
$('.problem-content .typo').append(document.getElementsByClassName('nav__item--round').length $('.problem-content .typo').append(document.getElementsByClassName('nav__item--round').length
? `<input type="submit" disabled class="button rounded primary disabled" value="${i18n('Login to Submit')}" />` ? `<input type="submit" disabled class="button rounded primary disabled" value="${i18n('Login to Submit')}" />`
: `<input type="submit" class="button rounded primary" value="${i18n('Submit')}" />`); : `<input type="submit" class="button rounded primary" value="${i18n('Submit')}" />`);
$('input.objective-input[type!=checkbox]').on('input', (e) => { $('.objective-input[type!=checkbox]').on('input', (e) => {
ans[e.target.name] = e.target.value; ans[e.target.name] = e.target.value;
}); });
$('input.objective-input[type=checkbox]').on('input', (e) => { $('input.objective-input[type=checkbox]').on('input', (e) => {

Loading…
Cancel
Save