Merge pull request #394 from nextcloud/fix/multiple_input_followup

Fix some small MultipleInput issues
This commit is contained in:
Jan C. Borchardt 2020-06-10 00:39:07 +02:00 committed by GitHub
commit 0472f3036c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,7 +76,8 @@
:maxlength="maxStringLengths.optionText" :maxlength="maxStringLengths.optionText"
minlength="1" minlength="1"
type="text" type="text"
@click="addNewEntry"> @click="addNewEntry"
@focus="addNewEntry">
</li> </li>
</ul> </ul>
</Question> </Question>
@ -221,6 +222,9 @@ export default {
* Add a new empty answer locally * Add a new empty answer locally
*/ */
addNewEntry() { addNewEntry() {
// If entering from non-edit-mode (possible by click), activate edit-mode
this.edit = true
// Add local entry // Add local entry
const options = this.options.slice() const options = this.options.slice()
options.push({ options.push({
@ -258,22 +262,28 @@ export default {
* @param {number} id the options id * @param {number} id the options id
*/ */
deleteOption(id) { deleteOption(id) {
// Remove entry
const options = this.options.slice() const options = this.options.slice()
const optionIndex = options.findIndex(option => option.id === id) const optionIndex = options.findIndex(option => option.id === id)
const option = Object.assign({}, this.options[optionIndex])
// delete locally if (options.length === 1) {
options.splice(optionIndex, 1) // Clear Text, but don't remove. Will be removed, when leaving edit-mode
options[0].text = ''
} else {
// Remove entry
const option = Object.assign({}, this.options[optionIndex])
// delete from Db // delete locally
this.deleteOptionFromDatabase(option) options.splice(optionIndex, 1)
// delete from Db
this.deleteOptionFromDatabase(option)
}
// Update question // Update question
this.updateOptions(options) this.updateOptions(options)
this.$nextTick(() => { this.$nextTick(() => {
this.focusIndex(optionIndex) this.focusIndex(optionIndex - 1)
}) })
}, },