0

Is there in VueJS a way to bind an inputbox to another inputbox, but only one way?

I want to make a copy of box1 to box2 while typing. But when I start editing box2 I want nothing to happen. (Box2 also has a binding to another field with VueJS)

Seems that my existing jQuery on(click) handler is overruled by Vue...

2 Answers 2

2

Bind the first box to a v-model, then bind the second boxes "value" attribute the box1's model. You can give box2 its own model and it should work as well.

<div id="app">
    <input type="text" v-model="box1">
    <input type="text" v-model="box2" :value="box1">
</div>

vm = new Vue({
        el: '#app',
        data: {
            box1: '',
            box2: ''
        }
    })

Sign up to request clarification or add additional context in comments.

Comments

0

Got it :) Just add a method for this feature.

<input v-model="productName" v-on:keyup="updateSKU" type="text">

new Vue({
  el: '#app',
  data : {
    productName : '',
    productSku : ''
  },
  methods : {
    updateSKU : function() {
      this.productSku = this.productName.toUpperCase();
    }
  }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.