Skip to content

Commit

Permalink
fix empty option bug
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Dec 24, 2022
1 parent b841968 commit b378a00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/components/Questions/AnswerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div :is="pseudoIcon"
v-if="!isDropdown"
class="question__item__pseudoInput" />
<textarea ref="input"
<input ref="input"
:aria-label="t('forms', 'An answer for the {index} option', { index: index + 1 })"
:placeholder="t('forms', 'Answer number {index}', { index: index + 1 })"
:value="answer.text"
Expand All @@ -12,10 +12,10 @@
:maxlength="maxOptionLength"
minlength="1"
type="text"
rows="1"
@input="onInput"
@keydown.delete="deleteEntry"
@keydown.enter.prevent="addNewEntry" />
@keydown.enter.prevent="addNewEntry">

<!-- Delete answer -->
<NcActions>
<NcActionButton @click="deleteEntry">
Expand Down Expand Up @@ -111,22 +111,17 @@ export default {
// clone answer
const answer = Object.assign({}, this.answer)
answer.text = this.$refs.input.value
let multipleAnswers = answer.text.split(/\r?\n/g)
multipleAnswers = multipleAnswers.filter(answer => { return answer.trim().length > 0 })
if (multipleAnswers.length > 1) {
// extract all answer entries to parent
this.$emit('multiple-answers', multipleAnswers, this.answer)
return
}
if (this.answer.local) {
// Dispatched for creation. Marked as synced
// eslint-disable-next-line vue/no-mutating-props
this.answer.local = false
const newAnswer = await this.debounceCreateAnswer(answer)
// Forward changes, but use current answer.text to avoid erasing
// any in-between changes while creating the answer
Object.assign(newAnswer, { text: answer.text })
Object.assign(newAnswer, { text: this.$refs.input.value })
this.$emit('update:answer', answer.id, newAnswer)
} else {
this.debounceUpdateAnswer(answer)
Expand Down Expand Up @@ -226,7 +221,6 @@ export default {
width: 100%;
position: relative;
margin-right: 2px !important;
resize: none;
&--shifted {
left: -30px;
Expand Down
1 change: 1 addition & 0 deletions src/components/Questions/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export default {
onMultipleOptions() {
this.isModalOpen = false
this.$nextTick(() => {
this.$emit('update:edit', true)
if (this.multipleOptions.length > 1) {
// extract all options entries to parent
this.$emit('multiple-answers', this.multipleOptions)
Expand Down
8 changes: 8 additions & 0 deletions src/components/Questions/QuestionDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ export default {
},
},

mounted() {
// Init selected options from values prop
if (this.values) {
const selected = this.values.map(id => this.options.find(option => option.id === id))
this.selectedOption = this.isMultiple ? selected : selected[0]
}
},

methods: {
onSelect(option) {
// Simple select
Expand Down
2 changes: 2 additions & 0 deletions src/components/Questions/QuestionMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default {
// Radio: create array
this.$emit('update:values', [this.questionValues])
},

/**
* Is the provided answer required ?
* This is needed for checkboxes as html5
Expand Down Expand Up @@ -244,6 +245,7 @@ export default {
text: '',
local: true,
})

// Update question
this.updateOptions(options)

Expand Down

0 comments on commit b378a00

Please sign in to comment.