From cd65bea28cf9eab0d92321f0276b3b0b75ff03f6 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 2 Sep 2021 11:00:03 +0200 Subject: [PATCH] Add 'Answer as ...' in forms --- www/form/app-form.less | 4 ++++ www/form/inner.js | 27 ++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/www/form/app-form.less b/www/form/app-form.less index 738909e1d..d17045009 100644 --- a/www/form/app-form.less +++ b/www/form/app-form.less @@ -331,6 +331,10 @@ margin-left: 10px; } } + .cp-form-anon-answer-registered { + font-style: italic; + margin-left: 10px; + } } } diff --git a/www/form/inner.js b/www/form/inner.js index d2621f257..9dc726ee4 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -2346,6 +2346,7 @@ define([ } else if (content.answers.anonymous) { // Answers aren't anonymous and guests are allowed // Guests can set a username and logged in users can answer anonymously + var $anon; if (!loggedIn) { anonName = h('div.cp-form-anon-answer-input', [ Messages.form_answerAs, @@ -2355,15 +2356,24 @@ define([ }) ]); $anonName = $(anonName).hide(); - $anonBox.on('change', function () { - if (Util.isChecked($anonBox)) { $anonName.hide(); } - else { $anonName.show(); } - }); } else if (APP.cantAnon) { // You've already answered with your credentials $cbox.hide(); $anonBox.attr('disabled', 'disabled').prop('checked', false); } + if (!anonName) { + anonName = h('div.cp-form-anon-answer-input', [ + Messages.form_answerAs, + h('span.cp-form-anon-answer-registered', user.nameĀ || Messages.anonymous) + ]); + } + if (!APP.cantAnon) { + var $anon = $(anonName).hide(); + $anonBox.on('change', function () { + if (Util.isChecked($anonBox)) { $anon.hide(); } + else { $anon.show(); } + }); + } } else { // Answers don't have to be anonymous and only logged in users can answer // ==> they have to answer with their keys so we know their name too @@ -2374,7 +2384,7 @@ define([ $cbox.after(h('div.alert.alert-info', Messages.form_authAnswer)); }); } - if (update && content.answers.cantEdit) { + if (update && content.answers.cantEdit || APP.isClosed) { $cbox.hide(); anonName = undefined; } @@ -3036,6 +3046,13 @@ define([ new Date(answers._time || APP.lastAnswerTime).toLocaleString()]))); } + if (APP.isClosed) { + APP.formBlocks.forEach(function (b) { + if (!b.setEditable) { return; } + b.setEditable(false); + }); + } + // In view mode, add "Submit" and "reset" buttons $container.append(makeFormControls(framework, content, Boolean(answers), evOnChange));