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
8 changes: 4 additions & 4 deletions src/components/Questions/QuestionDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
handle=".option__drag-handle"
invert-swap
tag="ul"
@change="saveOptionsOrder"
@change="saveOptionsOrder('choice')"
@start="isDragging = true"
@end="isDragging = false">
<TransitionGroup
Expand All @@ -62,7 +62,7 @@
<AnswerInput
v-for="(answer, index) in choices"
:key="answer.local ? 'option-local' : answer.id"
ref="input"

Check warning on line 65 in src/components/Questions/QuestionDropdown.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'input' is defined as ref, but never used
:answer="answer"
:form-id="formId"
is-dropdown
Expand All @@ -75,9 +75,9 @@
@update:answer="updateAnswer"
@delete="deleteOption"
@focus-next="focusNextInput"
@move-up="onOptionMoveUp(index)"
@move-down="onOptionMoveDown(index)"
@tabbed-out="checkValidOption" />
@move-up="onOptionMoveUp(index, 'choice')"
@move-down="onOptionMoveDown(index, 'choice')"
@tabbed-out="checkValidOption('choice')" />
</TransitionGroup>
</Draggable>
</template>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Questions/QuestionGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<AnswerInput
v-for="(answer, index) in columns"
:key="answer.local ? 'option-local' : answer.id"
ref="input"

Check warning on line 117 in src/components/Questions/QuestionGrid.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'input' is defined as ref, but never used
:answer="answer"
:form-id="formId"
:index="index"
Expand Down Expand Up @@ -154,7 +154,7 @@
<AnswerInput
v-for="(answer, index) in rows"
:key="answer.local ? 'option-local' : answer.id"
ref="input"

Check warning on line 157 in src/components/Questions/QuestionGrid.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'input' is defined as ref, but never used
:answer="answer"
:form-id="formId"
:index="index"
Expand Down Expand Up @@ -184,6 +184,7 @@
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import AnswerInput from './AnswerInput.vue'
import Question from './Question.vue'
import QuestionMixin from '../../mixins/QuestionMixin.js'
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'
import { GridCellType, OptionType } from '../../models/Constants.ts'
Expand All @@ -198,6 +199,7 @@
NcInputField,
NcLoadingIcon,
NcNoteCard,
Question,
},

mixins: [QuestionMixin, QuestionMultipleMixin],
Expand Down
34 changes: 23 additions & 11 deletions src/components/Questions/QuestionMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
:model-value="!!extraSettings?.optionsLimitMax"
@update:model-value="
(checked) =>
onLimitOptionsMax(
checked ? sortedOptions.length || 1 : null,
)
onLimitOptionsMax(checked ? choices.length || 1 : null)
">
{{ t('forms', 'Require a maximum of options to be checked') }}
</NcActionCheckbox>
Expand All @@ -75,7 +73,7 @@
{{ errorMessage }}
</NcNoteCard>
<NcCheckboxRadioSwitch
v-for="answer in sortedOptions"
v-for="answer in choices"
:key="answer.id"
:aria-errormessage="hasError ? errorId : undefined"
:aria-invalid="hasError ? 'true' : undefined"
Expand Down Expand Up @@ -118,14 +116,14 @@
</div>
<Draggable
v-else
v-model="sortedOptions"
v-model="choices"
class="question__content"
animation="200"
direction="vertical"
handle=".option__drag-handle"
invert-swap
tag="ul"
@change="saveOptionsOrder"
@change="saveOptionsOrder('choice')"
@start="isDragging = true"
@end="isDragging = false">
<TransitionGroup
Expand All @@ -136,22 +134,23 @@
">
<!-- Answer text input edit -->
<AnswerInput
v-for="(answer, index) in sortedOptions"
v-for="(answer, index) in choices"
:key="answer.local ? 'option-local' : answer.id"
ref="input"

Check warning on line 139 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"
:form-id="formId"
:index="index"
:is-unique="isUnique"
:max-index="options.length - 1"
:max-option-length="maxStringLengths.optionText"
option-type="choice"
@create-answer="onCreateAnswer"
@update:answer="updateAnswer"
@delete="deleteOption"
@focus-next="focusNextInput"
@move-up="onOptionMoveUp(index)"
@move-down="onOptionMoveDown(index)"
@tabbed-out="checkValidOption" />
@move-up="onOptionMoveUp(index, 'choice')"
@move-down="onOptionMoveDown(index, 'choice')"
@tabbed-out="checkValidOption('choice')" />
</TransitionGroup>
</Draggable>
<li
Expand Down Expand Up @@ -196,7 +195,10 @@
import Question from './Question.vue'
import QuestionMixin from '../../mixins/QuestionMixin.js'
import QuestionMultipleMixin from '../../mixins/QuestionMultipleMixin.ts'
import { QUESTION_EXTRASETTINGS_OTHER_PREFIX } from '../../models/Constants.ts'
import {
OptionType,
QUESTION_EXTRASETTINGS_OTHER_PREFIX,
} from '../../models/Constants.ts'

export default {
name: 'QuestionMultiple',
Expand Down Expand Up @@ -288,6 +290,16 @@
v.startsWith(QUESTION_EXTRASETTINGS_OTHER_PREFIX),
)
},

choices: {
get() {
return this.sortOptionsOfType(this.options, OptionType.Choice)
},

set(value) {
this.updateOptionsOrder(value, OptionType.Choice)
},
},
},

watch: {
Expand Down
8 changes: 2 additions & 6 deletions src/mixins/QuestionMultipleMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { generateOcsUrl } from '@nextcloud/router'
import debounce from 'debounce'
import { defineComponent } from 'vue'
import { INPUT_DEBOUNCE_MS } from '../models/Constants.ts'
import { INPUT_DEBOUNCE_MS, OptionType } from '../models/Constants.ts'
import logger from '../utils/Logger.js'

export default defineComponent({
Expand All @@ -31,17 +31,13 @@
return this.answerType.validate(this)
},

hasNoAnswer() {
return this.options.length === 0
},

isLastEmpty() {
const value = this.options[this.options.length - 1]
return value?.text?.trim?.().length === 0
},

expectedOptionTypes() {
return ['row', 'column']
return [OptionType.Choice, OptionType.Row, OptionType.Column]
},

sortedOptionsPerType(): { [key: string]: FormsOption[] } {
Expand Down Expand Up @@ -171,7 +167,7 @@
)
},

/**

Check warning on line 170 in src/mixins/QuestionMultipleMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

JSDoc @return declaration present but return expression not available in function
* Handles the creation of a new answer option.
*
* @param index the index of the answer
Expand Down Expand Up @@ -236,7 +232,7 @@
/**
* Remove any empty options when leaving an option
*
* @param optionType

Check warning on line 235 in src/mixins/QuestionMultipleMixin.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @param "optionType" description
*/
checkValidOption(optionType: string) {
// When leaving edit mode, filter and delete empty options
Expand Down
Loading