diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 2da1d8a..4a45592 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -40,14 +40,15 @@ use OCA\Forms\Db\SubmissionMapper; use OCA\Forms\Service\FormsService; use OCP\AppFramework\Controller; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\IMapperException; use OCP\AppFramework\Http; -use OCP\ILogger; use OCP\IL10N; +use OCP\ILogger; use OCP\IRequest; use OCP\IUser; -use OCP\IUserSession; use OCP\IUserManager; +use OCP\IUserSession; use OCP\Security\ISecureRandom; class ApiController extends Controller { @@ -725,7 +726,11 @@ class ApiController extends Controller { } foreach ($answerArray as $answer) { - if ($question['type'] === 'multiple' || $question['type'] === 'multiple_unique') { + // Are we using answer ids as values + if ($question['type'] === 'multiple' + || $question['type'] === 'multiple_unique' + || $question['type'] === 'dropdown') { + // Search corresponding option, skip processing if not found $optionIndex = array_search($answer, array_column($question['options'], 'id')); if ($optionIndex === false) { diff --git a/src/components/Questions/QuestionDropdown.vue b/src/components/Questions/QuestionDropdown.vue index 3a855a1..ac543f3 100644 --- a/src/components/Questions/QuestionDropdown.vue +++ b/src/components/Questions/QuestionDropdown.vue @@ -40,13 +40,15 @@ :name="text" :multiple="isMultiple" :required="mandatory" - class="question__content"> + class="question__content" + @change="onChange"> @@ -152,25 +154,20 @@ export default { }, methods: { - onChange(event, answerId) { - const isChecked = event.target.checked === true - let values = this.values.slice() + onChange(event) { + // Get all selected options + const answerIds = [...event.target.options] + .filter(option => option.selected) + .map(option => parseInt(option.value, 10)) // Simple select if (!this.isMultiple) { - this.$emit('update:values', [answerId]) + this.$emit('update:values', [answerIds[0]]) return } - // Select with multiple - if (isChecked) { - values.push(answerId) - } else { - values = values.filter(id => id !== answerId) - } - // Emit values and remove duplicates - this.$emit('update:values', [...new Set(values)]) + this.$emit('update:values', [...new Set(answerIds)]) }, /** diff --git a/src/views/Submit.vue b/src/views/Submit.vue index e6e904f..7fd055b 100644 --- a/src/views/Submit.vue +++ b/src/views/Submit.vue @@ -167,6 +167,7 @@ export default { onKeydownEnter(event) { const formInputs = Array.from(this.$refs.form) const sourceInputIndex = formInputs.findIndex(input => input === event.originalTarget) + // Focus next form element formInputs[sourceInputIndex + 1].focus() },