From 7ae59b6a4bf5c8ea57750400673d0f4a251af6eb Mon Sep 17 00:00:00 2001 From: Jonas Rittershofer Date: Tue, 26 May 2020 18:01:48 +0200 Subject: [PATCH] Show question invalid warning Signed-off-by: Jonas Rittershofer Co-authored-by: Jan-Christoph Borchardt --- src/components/Questions/Question.vue | 24 +++++++++++++++++++ src/components/Questions/QuestionLong.vue | 1 + src/components/Questions/QuestionMultiple.vue | 6 +++++ src/components/Questions/QuestionShort.vue | 1 + src/models/AnswerTypes.js | 5 ++++ 5 files changed, 37 insertions(+) diff --git a/src/components/Questions/Question.vue b/src/components/Questions/Question.vue index 2d8121e..1ea8711 100644 --- a/src/components/Questions/Question.vue +++ b/src/components/Questions/Question.vue @@ -46,6 +46,10 @@ required @input="onTitleChange">

+
@@ -114,6 +118,14 @@ export default { type: Number, required: true, }, + contentValid: { + type: Boolean, + default: true, + }, + warningInvalid: { + type: String, + default: t('forms', 'This question needs a title!'), + }, }, computed: { @@ -127,6 +139,14 @@ export default { } return this.text }, + + /** + * Question valid, if text not empty and content valid + * @returns {Boolean} true if question valid + */ + questionValid() { + return this.text && this.contentValid + }, }, methods: { @@ -240,6 +260,10 @@ export default { border-bottom-color: var(--color-border-dark); } + &-warning { + padding: 22px; + } + &-menu.action-item { position: sticky; top: var(--header-height); diff --git a/src/components/Questions/QuestionLong.vue b/src/components/Questions/QuestionLong.vue index 6870ced..29c89f2 100644 --- a/src/components/Questions/QuestionLong.vue +++ b/src/components/Questions/QuestionLong.vue @@ -29,6 +29,7 @@ :read-only="readOnly" :max-question-length="maxStringLengths.questionText" :title-placeholder="answerType.titlePlaceholder" + :warning-invalid="answerType.warningInvalid" @update:text="onTitleChange" @update:mandatory="onMandatoryChange" @delete="onDelete"> diff --git a/src/components/Questions/QuestionMultiple.vue b/src/components/Questions/QuestionMultiple.vue index bde4f91..abdfa3a 100644 --- a/src/components/Questions/QuestionMultiple.vue +++ b/src/components/Questions/QuestionMultiple.vue @@ -29,6 +29,8 @@ :read-only="readOnly" :max-question-length="maxStringLengths.questionText" :title-placeholder="answerType.titlePlaceholder" + :warning-invalid="answerType.warningInvalid" + :content-valid="contentValid" :shift-drag-handle="shiftDragHandle" @update:text="onTitleChange" @update:mandatory="onMandatoryChange" @@ -108,6 +110,10 @@ export default { mixins: [QuestionMixin], computed: { + contentValid() { + return this.answerType.validate(this) + }, + isLastEmpty() { const value = this.options[this.options.length - 1] return value?.text?.trim().length === 0 diff --git a/src/components/Questions/QuestionShort.vue b/src/components/Questions/QuestionShort.vue index 8ebc914..42c2288 100644 --- a/src/components/Questions/QuestionShort.vue +++ b/src/components/Questions/QuestionShort.vue @@ -29,6 +29,7 @@ :read-only="readOnly" :max-question-length="maxStringLengths.questionText" :title-placeholder="answerType.titlePlaceholder" + :warning-invalid="answerType.warningInvalid" @update:text="onTitleChange" @update:mandatory="onMandatoryChange" @delete="onDelete"> diff --git a/src/models/AnswerTypes.js b/src/models/AnswerTypes.js index f9a6cfd..999a857 100644 --- a/src/models/AnswerTypes.js +++ b/src/models/AnswerTypes.js @@ -43,6 +43,7 @@ export default { * @prop titlePlaceholder The placeholder users see as empty question-title in edit-mode * @prop createPlaceholder *optional* The placeholder that is visible in edit-mode, to indicate a submission form-input field * @prop submitPlaceholder *optional* The placeholder that is visible in submit-mode, to indicate a form input-field + * @prop warningInvalid The warning users see in edit mode, if the question is invalid. */ multiple_unique: { @@ -52,6 +53,7 @@ export default { validate: question => question.options.length > 0, titlePlaceholder: t('forms', 'Multiple choice question title'), + warningInvalid: t('forms', 'This question needs a title and at least one answer!'), // Using the same vue-component as multiple, this specifies that the component renders as multiple_unique. unique: true, @@ -64,6 +66,7 @@ export default { validate: question => question.options.length > 0, titlePlaceholder: t('forms', 'Checkbox question title'), + warningInvalid: t('forms', 'This question needs a title and at least one answer!'), }, short: { @@ -74,6 +77,7 @@ export default { titlePlaceholder: t('forms', 'Short answer question title'), createPlaceholder: t('forms', 'People can enter a short answer'), submitPlaceholder: t('forms', 'Enter a short answer'), + warningInvalid: t('forms', 'This question needs a title!'), }, long: { @@ -84,6 +88,7 @@ export default { titlePlaceholder: t('forms', 'Long text question title'), createPlaceholder: t('forms', 'People can enter a long text'), submitPlaceholder: t('forms', 'Enter a long text'), + warningInvalid: t('forms', 'This question needs a title!'), }, }