Skip to content

Commit

Permalink
feat: Add support for adding new entries with IME input
Browse files Browse the repository at this point in the history
The code changes in `QuestionMultiple.vue` allow for adding new entries with IME input, specifically for languages like Japanese or Chinese. This improvement ensures a better user experience when using IME input methods.

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
Chartman123 authored Jul 1, 2024
1 parent 4ede6cf commit 86bab53
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/components/Questions/QuestionMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -557,33 +557,37 @@ export default {
* Add a new empty answer locally
* @param {InputEvent} event The input event that triggered adding a new entry
*/
addNewEntry({ target }) {
// Add local entry
const options = [
...this.options,
{
id: GenRandomId(),
questionId: this.id,
text: target?.value ?? '',
local: true,
},
]

// Reset the "new answer" input if needed
if (this.$refs.pseudoInput) {
this.$refs.pseudoInput.value = ''
}
addNewEntry({ target, isComposing }) {
// Needed for languages using IME like Japanese or Chinese
if (!isComposing) {
// Add local entry
const options = [
...this.options,
{
id: GenRandomId(),
questionId: this.id,
text: target?.value ?? '',
local: true,
},
]

// Reset the "new answer" input if needed
if (this.$refs.pseudoInput) {
this.$refs.pseudoInput.value = ''
}

// Update questions
this.updateOptions(options)
// Update questions
this.updateOptions(options)

this.$nextTick(() => {
// Set focus to the created input element
this.focusIndex(options.length - 1)
this.$nextTick(() => {
// Set focus to the created input element
this.focusIndex(options.length - 1)

// Trigger onInput on new AnswerInput for posting the new option to the API
this.$refs.input[options.length - 1].onInput()
})
// Trigger onInput on new AnswerInput for posting the new option to the API
this.$refs.input[options.length - 1].onInput()
})
}
}
},

/**
Expand Down

0 comments on commit 86bab53

Please sign in to comment.