Skip to content

Commit 1cba4a2

Browse files
fix(ranking): restore local state, clear form sync and submit validation
Signed-off-by: paul bochtler <65470117+datapumpernickel@users.noreply.github.com>
1 parent 3ad8cd2 commit 1cba4a2

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/components/Questions/QuestionRanking.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:warningInvalid="answerType.warningInvalid"
1111
:contentValid="contentValid"
1212
:shiftDragHandle="shiftDragHandle"
13+
:errorMessage="errorMessage"
1314
v-on="commonListeners">
1415
<template #actions>
1516
<NcActionCheckbox
@@ -172,6 +173,7 @@
172173
</template>
173174

174175
<script>
176+
import { translate as t } from '@nextcloud/l10n'
175177
import { VueDraggable as Draggable } from 'vue-draggable-plus'
176178
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
177179
import NcActionCheckbox from '@nextcloud/vue/components/NcActionCheckbox'
@@ -215,6 +217,7 @@ export default {
215217
216218
data() {
217219
return {
220+
errorMessage: null,
218221
isDragging: false,
219222
isLoading: false,
220223
isOptionDialogShown: false,
@@ -251,9 +254,39 @@ export default {
251254
this.initRankedOptions()
252255
},
253256
},
257+
258+
values: {
259+
immediate: true,
260+
handler() {
261+
this.initRankedOptions()
262+
},
263+
},
254264
},
255265
256266
methods: {
267+
async validate() {
268+
const optionsCount = this.sortOptionsOfType(
269+
this.options,
270+
OptionType.Choice,
271+
).length
272+
273+
if (this.isRequired && this.rankedOptions.length === 0) {
274+
this.errorMessage = t('forms', 'You must choose at least one option')
275+
return false
276+
}
277+
278+
if (
279+
this.rankedOptions.length > 0
280+
&& this.rankedOptions.length !== optionsCount
281+
) {
282+
this.errorMessage = t('forms', 'You must rank all options')
283+
return false
284+
}
285+
286+
this.errorMessage = null
287+
return true
288+
},
289+
257290
/**
258291
* Initialize ranked/unranked options from existing values or default order
259292
*/

src/views/Submit.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,12 @@ export default {
575575
continue
576576
}
577577
578-
answers[questionId] =
579-
answer.type === 'QuestionMultiple'
580-
? answer.value.map(String)
581-
: answer.value
578+
answers[questionId] = [
579+
'QuestionMultiple',
580+
'QuestionRanking',
581+
].includes(answer.type)
582+
? answer.value.map(String)
583+
: answer.value
582584
}
583585
this.answers = answers
584586
},

0 commit comments

Comments
 (0)