Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public function getQuestions(int $formId): array {
}
}

// Set `isRequired` if minimum options limit is set
if ($question['type'] === Constants::ANSWER_TYPE_MULTIPLE && $question['extraSettings']['optionsLimitMin'] > 0) {
$question['isRequired'] = true;
}

$questionList[] = $question;
}
} catch (DoesNotExistException $e) {
Expand Down
16 changes: 16 additions & 0 deletions src/components/Questions/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
v-html="computedDescription" />
<!-- eslint-enable vue/no-v-html -->
</div>
<NcNoteCard v-if="hasInfo" :id="infoId" type="info">
Comment thread
Chartman123 marked this conversation as resolved.
{{ infoMessage }}
</NcNoteCard>
<NcNoteCard v-if="hasError" :id="errorId" type="error">
{{ errorMessage }}
</NcNoteCard>
Expand Down Expand Up @@ -241,7 +244,7 @@

contentValid: {
type: Boolean,
default: true,

Check warning on line 247 in src/components/Questions/Question.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Boolean prop should only be defaulted to false
},

warningInvalid: {
Expand All @@ -263,6 +266,11 @@
type: String,
default: null,
},

infoMessage: {
type: String,
default: null,
},
},

emits: [
Expand Down Expand Up @@ -336,9 +344,17 @@
return !!this.errorMessage
},

hasInfo() {
return !!this.infoMessage
},

errorId() {
return `q${this.index}_error`
},

infoId() {
return `q${this.index}_info`
},
},

// Ensure description is sized correctly on initial render
Expand Down
83 changes: 81 additions & 2 deletions src/components/Questions/QuestionMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:contentValid="contentValid"
:shiftDragHandle="shiftDragHandle"
:errorMessage="errorMessage"
:infoMessage="infoMessage"
v-on="commonListeners">
<template #actions>
<NcActionCheckbox
Expand Down Expand Up @@ -76,6 +77,7 @@
<NcCheckboxRadioSwitch
v-for="answer in choices"
:key="answer.id"
:aria-describedby="hasInfo ? infoId : undefined"
:aria-errormessage="hasError ? errorId : undefined"
:aria-invalid="hasError ? 'true' : undefined"
:modelValue="questionValues"
Expand Down Expand Up @@ -135,7 +137,7 @@
<AnswerInput
v-for="(answer, index) in choices"
:key="answer.local ? 'option-local' : answer.id"
ref="input"

Check warning on line 140 in src/components/Questions/QuestionMultiple.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'input' is defined as ref, but never used
:answer="answer"
:formId="formId"
:index="index"
Expand Down Expand Up @@ -219,7 +221,7 @@
},

mixins: [QuestionMixin, QuestionMultipleMixin],
emits: ['update:values'],
emits: ['update:values', 'update:isRequired'],

setup() {
return {
Expand Down Expand Up @@ -292,6 +294,54 @@
this.updateOptionsOrder(value, OptionType.Choice)
},
},

availableOptions() {
return (
this.choices.filter(({ text }) => text.trim() !== '').length
+ (this.allowOtherAnswer ? 1 : 0)
)
},

infoMessage() {
const min = this.extraSettings?.optionsLimitMin ?? 0
const max = this.extraSettings?.optionsLimitMax ?? 0

if (!min && !max) {
return null
}

if (min && max) {
if (min === max) {
return n(
'forms',
'Choose exactly one option',
'Choose exactly %n options',
min,
)
}

return t('forms', 'Choose between {min} and {max} options', {
min,
max,
})
}

if (min) {
return n(
'forms',
'Choose at least one option',
'Choose at least %n options',
min,
)
}

return n(
'forms',
'Choose at most one option',
'Choose at most %n options',
max,
)
},
},

watch: {
Expand All @@ -316,7 +366,7 @@
this.errorMessage = n(
'forms',
'You must choose at most one option',
'You must choose a maximum of %n options',
'You must choose at most %n options',
max,
)
return false
Expand Down Expand Up @@ -386,6 +436,19 @@
// For unique (radio) options we cannot set limits, also if null is passed then we need to remove the limit
this.onExtraSettingsChange({ optionsLimitMax: undefined })
} else if (max) {
if (max > this.availableOptions) {
showError(
t(
'forms',
'Upper options limit must not exceed the number of available options',
),
)
this.onExtraSettingsChange({
optionsLimitMax: this.availableOptions || undefined,
})
return
}

if ((this.extraSettings.optionsLimitMin ?? 0) > max) {
showError(
t(
Expand All @@ -410,6 +473,19 @@
if (this.isUnique || min === null) {
this.onExtraSettingsChange({ optionsLimitMin: undefined })
} else if (min) {
if (min > this.availableOptions - 1) {
showError(
t(
'forms',
'Lower options limit must be smaller than the number of available options',
),
)
this.onExtraSettingsChange({
optionsLimitMin: this.availableOptions - 1 || undefined,
})
return
}

if (
this.extraSettings.optionsLimitMax
&& min > this.extraSettings.optionsLimitMax
Expand All @@ -423,6 +499,9 @@
return
}
this.onExtraSettingsChange({ optionsLimitMin: min })
if (min > 0) {
this.$emit('update:isRequired', true)
}
}
},

Expand Down
10 changes: 9 additions & 1 deletion src/mixins/QuestionMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ export default {
return !!this.errorMessage
},

hasInfo() {
return !!this.infoMessage
},

errorId() {
return 'q' + this.index + '_error'
return `q${this.index}_error`
},

infoId() {
Comment thread
Chartman123 marked this conversation as resolved.
return `q${this.index}_info`
},

/**
Expand Down
Loading