diff --git a/src/components/Questions/AnswerInput.vue b/src/components/Questions/AnswerInput.vue index a416420bf6..7b625768bd 100644 --- a/src/components/Questions/AnswerInput.vue +++ b/src/components/Questions/AnswerInput.vue @@ -3,7 +3,7 @@
- + @keydown.enter.prevent="addNewEntry"> @@ -112,6 +112,30 @@ export default { const answer = Object.assign({}, this.answer) answer.text = this.$refs.input.value + if(!this.isUnique){ + const multipleAswers= this.$refs.input.value.split(/\r?\n/g) + if(multipleAswers.length>1){ + /*for (let i = 1; i < multipleAswers.length; i++) { + var option = + { + id: GenRandomId(), + questionId: this.id, + text: multipleAswers[i], + local: true, + } + + + + console.log(multipleAswers.slice(1));*/ + + this.$emit('multipleAswers',multipleAswers,answer.id) + //this.$emit('update:answer') + return + } + + + } + if (this.answer.local) { // Dispatched for creation. Marked as synced @@ -221,6 +245,7 @@ export default { width: 100%; position: relative; margin-right: 2px !important; + resize: none; &--shifted { left: -30px; diff --git a/src/components/Questions/QuestionMultiple.vue b/src/components/Questions/QuestionMultiple.vue index 1b92c58479..e7c868135b 100644 --- a/src/components/Questions/QuestionMultiple.vue +++ b/src/components/Questions/QuestionMultiple.vue @@ -66,7 +66,8 @@ :max-option-length="maxStringLengths.optionText" @add="addNewEntry" @delete="deleteOption" - @update:answer="updateAnswer" /> + @update:answer="updateAnswer" + @multipleAswers="handleMultipleOptions" />
  • @@ -98,6 +99,7 @@ import QuestionMixin from '../../mixins/QuestionMixin.js' import GenRandomId from '../../utils/GenRandomId.js' import logger from '../../utils/Logger.js' + export default { name: 'QuestionMultiple', @@ -180,7 +182,45 @@ export default { // Radio: create array this.$emit('update:values', [this.questionValues]) }, + async handleMultipleOptions(answers,id){ + //step 1: create copy of options to update + //step 2: update options[id] to include the first answers + //step 3: add the rest of options to the end + this.edit = true + let options = this.options.slice() + // console.log(options) + for (let i = 0; i < answers.length; i++) { + if (i === 0) { + const answerIndex = options.findIndex(option => option.id === id) + console.log('charmouta',options[answerIndex].text) + let isasba =options[answerIndex].text.trim().length > 0 + options[answerIndex].text = answers[0] + if(isasba){ + this.$emit('update:answer', options[answerIndex].id, options[answerIndex].text) + + continue + } + + } + else{ + options.push({ + id: GenRandomId(), + questionId: this.id, + text: answers[i], + local: true, + })} + + await axios.post(generateOcsUrl('apps/forms/api/v2/option'), { + questionId: this.id, + text: answers[i], + }) + } + this.updateOptions(options) + this.$nextTick(() => { + this.focusIndex(options.length - 1) + }) + }, /** * Is the provided answer required ? * This is needed for checkboxes as html5 @@ -238,13 +278,12 @@ export default { // Add local entry const options = this.options.slice() - options.push({ + options.push({ id: GenRandomId(), questionId: this.id, text: '', local: true, }) - // Update question this.updateOptions(options)