Skip to content

Commit 85622e6

Browse files
authored
Merge pull request #2800 from nextcloud/backport/2689/stable5
[stable5] chore(QuestionMultiple): update "Other" answer handling to use v-model and add change handler
2 parents b4aedaa + 7e61f9f commit 85622e6

1 file changed

Lines changed: 36 additions & 34 deletions

File tree

src/components/Questions/QuestionMultiple.vue

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
class="question__input"
107107
:label="placeholderOtherAnswer"
108108
:required="otherAnswer !== undefined"
109-
:value.sync="otherAnswerText" />
109+
:model-value="cachedOtherAnswerText"
110+
@update:model-value="onOtherAnswerTextChange" />
110111
</div>
111112
</fieldset>
112113
</template>
@@ -287,39 +288,6 @@ export default {
287288
v.startsWith(QUESTION_EXTRASETTINGS_OTHER_PREFIX),
288289
)
289290
},
290-
291-
/**
292-
* The text value of the "other" answer
293-
*/
294-
otherAnswerText: {
295-
get() {
296-
return this.cachedOtherAnswerText
297-
},
298-
/**
299-
* Called when the value of the "other" anwer is changed input
300-
* @param {string} value the new text of the "other" answer
301-
*/
302-
set(value) {
303-
this.cachedOtherAnswerText = value
304-
// Prefix the value
305-
const prefixedValue = `${QUESTION_EXTRASETTINGS_OTHER_PREFIX}${value}`
306-
// emit the values and add the "other" answer
307-
this.$emit(
308-
'update:values',
309-
this.isUnique
310-
? [prefixedValue]
311-
: [
312-
...this.values.filter(
313-
(v) =>
314-
!v.startsWith(
315-
QUESTION_EXTRASETTINGS_OTHER_PREFIX,
316-
),
317-
),
318-
prefixedValue,
319-
],
320-
)
321-
},
322-
},
323291
},
324292
325293
watch: {
@@ -483,6 +451,40 @@ export default {
483451
onAllowOtherAnswerChange(allowOtherAnswer) {
484452
return this.onExtraSettingsChange({ allowOtherAnswer })
485453
},
454+
455+
/**
456+
* Handles the change event for the "Other" answer text input.
457+
*
458+
* @param {string} value - The new value entered for the "Other" answer.
459+
*
460+
* This method performs the following actions:
461+
* 1. Updates the cached value of the "Other" answer text (`cachedOtherAnswerText`).
462+
* 2. Prefixes the input value with a predefined constant (`QUESTION_EXTRASETTINGS_OTHER_PREFIX`).
463+
* 3. Emits an `update:values` event with the updated list of values:
464+
* - If `isUnique` is true, the emitted values will only include the prefixed "Other" answer.
465+
* - If `isUnique` is false, the emitted values will include all existing values
466+
* (excluding any that start with the "Other" prefix) and the new prefixed "Other" answer.
467+
*/
468+
onOtherAnswerTextChange(value) {
469+
this.cachedOtherAnswerText = value
470+
// Prefix the value
471+
const prefixedValue = `${QUESTION_EXTRASETTINGS_OTHER_PREFIX}${value}`
472+
// emit the values and add the "other" answer
473+
this.$emit(
474+
'update:values',
475+
this.isUnique
476+
? [prefixedValue]
477+
: [
478+
...this.values.filter(
479+
(v) =>
480+
!v.startsWith(
481+
QUESTION_EXTRASETTINGS_OTHER_PREFIX,
482+
),
483+
),
484+
prefixedValue,
485+
],
486+
)
487+
},
486488
},
487489
}
488490
</script>

0 commit comments

Comments
 (0)