Fix dropdown submission insert
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
52cfe8c177
commit
d9ff7a180a
|
@ -40,14 +40,15 @@ use OCA\Forms\Db\SubmissionMapper;
|
||||||
use OCA\Forms\Service\FormsService;
|
use OCA\Forms\Service\FormsService;
|
||||||
|
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\IMapperException;
|
use OCP\AppFramework\Db\IMapperException;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\ILogger;
|
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
use OCP\ILogger;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserSession;
|
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
use OCP\IUserSession;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
|
|
||||||
class ApiController extends Controller {
|
class ApiController extends Controller {
|
||||||
|
@ -725,7 +726,11 @@ class ApiController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($answerArray as $answer) {
|
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
|
// Search corresponding option, skip processing if not found
|
||||||
$optionIndex = array_search($answer, array_column($question['options'], 'id'));
|
$optionIndex = array_search($answer, array_column($question['options'], 'id'));
|
||||||
if ($optionIndex === false) {
|
if ($optionIndex === false) {
|
||||||
|
|
|
@ -40,13 +40,15 @@
|
||||||
:name="text"
|
:name="text"
|
||||||
:multiple="isMultiple"
|
:multiple="isMultiple"
|
||||||
:required="mandatory"
|
:required="mandatory"
|
||||||
class="question__content">
|
class="question__content"
|
||||||
|
@change="onChange">
|
||||||
<option value="">
|
<option value="">
|
||||||
{{ selectOptionPlaceholder }}
|
{{ selectOptionPlaceholder }}
|
||||||
</option>
|
</option>
|
||||||
<option v-for="answer in options"
|
<option v-for="answer in options"
|
||||||
:key="answer.id"
|
:key="answer.id"
|
||||||
:value="answer.id">
|
:value="answer.id"
|
||||||
|
:selected="isChecked(answer.id)">
|
||||||
{{ answer.text }}
|
{{ answer.text }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
@ -152,25 +154,20 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onChange(event, answerId) {
|
onChange(event) {
|
||||||
const isChecked = event.target.checked === true
|
// Get all selected options
|
||||||
let values = this.values.slice()
|
const answerIds = [...event.target.options]
|
||||||
|
.filter(option => option.selected)
|
||||||
|
.map(option => parseInt(option.value, 10))
|
||||||
|
|
||||||
// Simple select
|
// Simple select
|
||||||
if (!this.isMultiple) {
|
if (!this.isMultiple) {
|
||||||
this.$emit('update:values', [answerId])
|
this.$emit('update:values', [answerIds[0]])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select with multiple
|
|
||||||
if (isChecked) {
|
|
||||||
values.push(answerId)
|
|
||||||
} else {
|
|
||||||
values = values.filter(id => id !== answerId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit values and remove duplicates
|
// Emit values and remove duplicates
|
||||||
this.$emit('update:values', [...new Set(values)])
|
this.$emit('update:values', [...new Set(answerIds)])
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -167,6 +167,7 @@ export default {
|
||||||
onKeydownEnter(event) {
|
onKeydownEnter(event) {
|
||||||
const formInputs = Array.from(this.$refs.form)
|
const formInputs = Array.from(this.$refs.form)
|
||||||
const sourceInputIndex = formInputs.findIndex(input => input === event.originalTarget)
|
const sourceInputIndex = formInputs.findIndex(input => input === event.originalTarget)
|
||||||
|
|
||||||
// Focus next form element
|
// Focus next form element
|
||||||
formInputs[sourceInputIndex + 1].focus()
|
formInputs[sourceInputIndex + 1].focus()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue