Skip to content

Commit 836614b

Browse files
committed
fix: dropdown anc checkboxes fields are broken after grid type introduction
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 7db3a28 commit 836614b

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

src/components/Questions/QuestionDropdown.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
handle=".option__drag-handle"
5050
invert-swap
5151
tag="ul"
52-
@change="saveOptionsOrder"
52+
@change="saveOptionsOrder('choice')"
5353
@start="isDragging = true"
5454
@end="isDragging = false">
5555
<TransitionGroup
@@ -75,9 +75,9 @@
7575
@update:answer="updateAnswer"
7676
@delete="deleteOption"
7777
@focus-next="focusNextInput"
78-
@move-up="onOptionMoveUp(index)"
79-
@move-down="onOptionMoveDown(index)"
80-
@tabbed-out="checkValidOption" />
78+
@move-up="onOptionMoveUp(index, 'choice')"
79+
@move-down="onOptionMoveDown(index, 'choice')"
80+
@tabbed-out="checkValidOption('choice')" />
8181
</TransitionGroup>
8282
</Draggable>
8383
</template>

src/components/Questions/QuestionGrid.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ import NcInputField from '@nextcloud/vue/components/NcInputField'
184184
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
185185
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
186186
import AnswerInput from './AnswerInput.vue'
187+
import Question from './Question.vue'
187188
import QuestionMixin from '../../mixins/QuestionMixin.js'
188189
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'
189190
import { GridCellType, OptionType } from '../../models/Constants.ts'
@@ -198,6 +199,7 @@ export default {
198199
NcInputField,
199200
NcLoadingIcon,
200201
NcNoteCard,
202+
Question,
201203
},
202204
203205
mixins: [QuestionMixin, QuestionMultipleMixin],

src/components/Questions/QuestionMultiple.vue

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
:model-value="!!extraSettings?.optionsLimitMax"
4848
@update:model-value="
4949
(checked) =>
50-
onLimitOptionsMax(
51-
checked ? sortedOptions.length || 1 : null,
52-
)
50+
onLimitOptionsMax(checked ? choices.length || 1 : null)
5351
">
5452
{{ t('forms', 'Require a maximum of options to be checked') }}
5553
</NcActionCheckbox>
@@ -75,7 +73,7 @@
7573
{{ errorMessage }}
7674
</NcNoteCard>
7775
<NcCheckboxRadioSwitch
78-
v-for="answer in sortedOptions"
76+
v-for="answer in choices"
7977
:key="answer.id"
8078
:aria-errormessage="hasError ? errorId : undefined"
8179
:aria-invalid="hasError ? 'true' : undefined"
@@ -118,14 +116,14 @@
118116
</div>
119117
<Draggable
120118
v-else
121-
v-model="sortedOptions"
119+
v-model="choices"
122120
class="question__content"
123121
animation="200"
124122
direction="vertical"
125123
handle=".option__drag-handle"
126124
invert-swap
127125
tag="ul"
128-
@change="saveOptionsOrder"
126+
@change="saveOptionsOrder('choice')"
129127
@start="isDragging = true"
130128
@end="isDragging = false">
131129
<TransitionGroup
@@ -136,7 +134,7 @@
136134
">
137135
<!-- Answer text input edit -->
138136
<AnswerInput
139-
v-for="(answer, index) in sortedOptions"
137+
v-for="(answer, index) in choices"
140138
:key="answer.local ? 'option-local' : answer.id"
141139
ref="input"
142140
:answer="answer"
@@ -145,13 +143,14 @@
145143
:is-unique="isUnique"
146144
:max-index="options.length - 1"
147145
:max-option-length="maxStringLengths.optionText"
146+
option-type="choice"
148147
@create-answer="onCreateAnswer"
149148
@update:answer="updateAnswer"
150149
@delete="deleteOption"
151150
@focus-next="focusNextInput"
152-
@move-up="onOptionMoveUp(index)"
153-
@move-down="onOptionMoveDown(index)"
154-
@tabbed-out="checkValidOption" />
151+
@move-up="onOptionMoveUp(index, 'choice')"
152+
@move-down="onOptionMoveDown(index, 'choice')"
153+
@tabbed-out="checkValidOption('choice')" />
155154
</TransitionGroup>
156155
</Draggable>
157156
<li
@@ -196,7 +195,10 @@ import AnswerInput from './AnswerInput.vue'
196195
import Question from './Question.vue'
197196
import QuestionMixin from '../../mixins/QuestionMixin.js'
198197
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'
199-
import { QUESTION_EXTRASETTINGS_OTHER_PREFIX } from '../../models/Constants.ts'
198+
import {
199+
OptionType,
200+
QUESTION_EXTRASETTINGS_OTHER_PREFIX,
201+
} from '../../models/Constants.ts'
200202
201203
export default {
202204
name: 'QuestionMultiple',
@@ -288,6 +290,16 @@ export default {
288290
v.startsWith(QUESTION_EXTRASETTINGS_OTHER_PREFIX),
289291
)
290292
},
293+
294+
choices: {
295+
get() {
296+
return this.sortOptionsOfType(this.options, OptionType.Choice)
297+
},
298+
299+
set(value) {
300+
this.updateOptionsOrder(value, OptionType.Choice)
301+
},
302+
},
291303
},
292304
293305
watch: {

src/mixins/QuestionMultipleMixin.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { translate as t } from '@nextcloud/l10n'
1212
import { generateOcsUrl } from '@nextcloud/router'
1313
import debounce from 'debounce'
1414
import { defineComponent } from 'vue'
15-
import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
15+
import { INPUT_DEBOUNCE_MS, OptionType } from '../models/Constants.ts'
1616
import logger from '../utils/Logger.js'
1717

1818
export default defineComponent({
@@ -31,17 +31,13 @@ export default defineComponent({
3131
return this.answerType.validate(this)
3232
},
3333

34-
hasNoAnswer() {
35-
return this.options.length === 0
36-
},
37-
3834
isLastEmpty() {
3935
const value = this.options[this.options.length - 1]
4036
return value?.text?.trim?.().length === 0
4137
},
4238

4339
expectedOptionTypes() {
44-
return ['row', 'column']
40+
return [OptionType.Choice, OptionType.Row, OptionType.Column]
4541
},
4642

4743
sortedOptionsPerType(): { [key: string]: FormsOption[] } {

0 commit comments

Comments
 (0)