File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 :warningInvalid =" answerType .warningInvalid "
1111 :contentValid =" contentValid "
1212 :shiftDragHandle =" shiftDragHandle "
13+ :errorMessage =" errorMessage "
1314 v-on =" commonListeners " >
1415 <template #actions >
1516 <NcActionCheckbox
172173</template >
173174
174175<script >
176+ import { translate as t } from ' @nextcloud/l10n'
175177import { VueDraggable as Draggable } from ' vue-draggable-plus'
176178import NcActionButton from ' @nextcloud/vue/components/NcActionButton'
177179import 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 */
Original file line number Diff line number Diff 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 },
You can’t perform that action at this time.
0 commit comments