I have an input wrapper component that has a Select and shows a Freeform text box where the user can enter an exact amount.
I can't figure out how to bind the Freeform text box to the parent field as well as the option the user selected. I'm not sure how to emit the change/input.
Trying to follow this from the Custom Events docs
Simple example here:
InputWrapper :
<template v-if="inputType === 'text'">
<input type="text" v-bind:value="value" v-bind="$attrs" v-on="inputListeners">
</template>
<template v-else-if="inputType === 'select'">
<select v-bind="$attrs" v-bind:value="value" v-on="inputListeners">
<option value>Select</option>
<option
v-for="option in options"
v-bind:value="option.Id"
v-bind:key="option.Id"
>{{option.Description}}</option>
</select>
<!--Only show the input if it's a "FreeformOption"-->
<!--How do I make this update the parent??-->
<input
type="text"
v-if="selectedOption.IsFreeformOption"
v-bind:value.sync="freeformValue"
v-bind="$attrs"
v-on:update="$emit('update:person.ExactIncome', '111')"
v-on:input="$emit('input:person.ExactIncome', '222')"
>
<!--Would ideally recursively call the InputWrapper component
<InputWrapper
inputType="text"
v-if="selectedOption.IsFreeformOption"
v-bind:value= "freeformValue"
v-on:input="$emit('input', $event)"
></InputWrapper>
-->
</template>
Demo:
<InputWrapper
id="incomeLevels"
inputType="select"
:options="incomeLevels"
:freeformValue.sync="person.ExactIncome"
v-model="person.IncomeLevelID"
></InputWrapper>
Working Demo:
Essential wrap the freeformValue in a computed and emit the change there.
wrappedFreeform: {
get() {
return this.freeformValue;
},
set(v) {
this.$emit("update:freeformValue", v);
}
}