|
106 | 106 | class="question__input" |
107 | 107 | :label="placeholderOtherAnswer" |
108 | 108 | :required="otherAnswer !== undefined" |
109 | | - :value.sync="otherAnswerText" /> |
| 109 | + :model-value="cachedOtherAnswerText" |
| 110 | + @update:model-value="onOtherAnswerTextChange" /> |
110 | 111 | </div> |
111 | 112 | </fieldset> |
112 | 113 | </template> |
@@ -287,39 +288,6 @@ export default { |
287 | 288 | v.startsWith(QUESTION_EXTRASETTINGS_OTHER_PREFIX), |
288 | 289 | ) |
289 | 290 | }, |
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 | | - }, |
323 | 291 | }, |
324 | 292 |
|
325 | 293 | watch: { |
@@ -483,6 +451,40 @@ export default { |
483 | 451 | onAllowOtherAnswerChange(allowOtherAnswer) { |
484 | 452 | return this.onExtraSettingsChange({ allowOtherAnswer }) |
485 | 453 | }, |
| 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 | + }, |
486 | 488 | }, |
487 | 489 | } |
488 | 490 | </script> |
|
0 commit comments