Skip to content

Commit 7940fb8

Browse files
committed
fix: prevent duplicate options and broken focus on answer creation
Remove the premature `update:answer` emit from `createLocalAnswer` in AnswerInput — after commit 61b3f48 passed the index correctly, both `updateAnswer` and `onCreateAnswer` were adding the new option, causing a duplicate (one without server ID, one with) that appeared unsaved. Also fix a misplaced closing parenthesis in `QuestionMultipleMixin.deleteOption` where `optionType` was passed as the second argument to `$nextTick` instead of to `focusIndex`, causing `focusIndex` to receive `undefined` as the option type and fail to focus the previous option after deletion. Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent 797512b commit 7940fb8

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/components/Questions/AnswerInput.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ export default {
350350
// Prevent any queued debounced PATCHes from running while creating
351351
this.queue.pause()
352352
try {
353-
// Dispatched for creation. Marked as synced
354-
this.$emit('update:answer', this.index, answer)
355353
const newAnswer = await this.createAnswer(answer)
356354
357355
// Forward changes, but use current answer.text to avoid erasing

src/mixins/QuestionMixin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ import OcsResponse2Data from '../utils/OcsResponse2Data.js'
1414

1515
export default {
1616
inheritAttrs: false,
17+
18+
emits: [
19+
'update:text',
20+
'update:description',
21+
'update:isRequired',
22+
'update:extraSettings',
23+
'update:name',
24+
'update:values',
25+
'delete',
26+
'clone',
27+
'keydown',
28+
'moveDown',
29+
'moveUp',
30+
],
31+
1732
props: {
1833
/**
1934
* Question-Id

src/mixins/QuestionMultipleMixin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { INPUT_DEBOUNCE_MS, OptionType } from '../models/Constants.ts'
1616
import logger from '../utils/Logger.js'
1717

1818
export default defineComponent({
19+
emits: ['update:options'],
20+
1921
data() {
2022
return {
2123
dirtyOptionsType: null,
@@ -268,7 +270,7 @@ export default defineComponent({
268270
)
269271

270272
// Focus the previous option
271-
this.$nextTick(() => this.focusIndex(Math.max(index - 1, 0)), optionType)
273+
this.$nextTick(() => this.focusIndex(Math.max(index - 1, 0), optionType))
272274
},
273275

274276
/**

0 commit comments

Comments
 (0)