AlexanderKim's avatar

2 way data-binding in inputs

Is it possible to use v-model on two inputs:

<form id="form-creator">
  <input v-model="calculate" type="text" name="text">
  <input value="@{{ calculate }} type="text" name="text-result">
</form>

I want to make calculations, e.g. if i type 1, it will make (1*750) and output that result on the second text-result. But it seems like v-model doesn't work with outputting result in another input.

0 likes
11 replies
zachleigh's avatar

Why is the second one an input? Does the user input anything?

Did you try using v-model on the second input?

AlexanderKim's avatar

@zachleigh, because it's a 2 way currency exchange calculator. Using the same v-model on the second value? It would duplicate it then.

zachleigh's avatar

Ah, I would use computed properties probably.

1 like
AlexanderKim's avatar

Thanks, but how to output result on the second input?

zachleigh's avatar

Maybe use v-model and a computed property, not the calculate property.

zachleigh's avatar

On mobile now. I will when I get home, if nobody does before that time.

richard's avatar

Here is my attempt on JSFiddle.

It requires you click ENTER after input though.

Please or to participate in this conversation.