Summer Sale! All accounts are 50% off this week.

nicktr's avatar

Setting Input Value attribute with Vue

I have a dynamically generated form using Vue. I'm trying to pre-populate the 'value' attribute of a hidden input but It's not working. From what i've read I see that Vue treats the value property differently, so using v-bind:value= etc doesn't work.

div class="form-element hidden">
            <input type="text" name="productId" :value="myProduct.id" readonly>
</div>

Any ideas how I would go about filling the value attribute? This doesn't need to be filled on page load, but just on clicking a search button, which returns a table of results.

Many thanks.

1 like
1 reply
erikverbeek's avatar

Vue shouldn't have any difficulties binding a property to the value attribute. As you can see in this example.

If you explicitly want to update it on the click of a button you can manually update the field with plain JS or jQuery. Or you set use a custom attribute that you update when the button is pressed.

Please or to participate in this conversation.