Search code examples
javascripthtmlformsqwebodoo-12

How to set value of form input field?


This is my form input field (without classes and such):

<input id="input_partnerID" type="value" name="partner_id" value=""/>

I want to set the input value to the contact id of the logged in user. I can get that value with this Qweb code:

<p id="value_parterID" t-esc="user_id.partner_id.id"/>

And to get that value in my input form I use this javascript. The method is called when the "accept terms and conditions" button is clicked.

     function getID() {
        document.getElementById("input_partnerID").value = document.getElementById("value_parterID").innerHTML;
     }

This works but probably isn't the most efficient way to do this.

How can I use Qweb to fill in the input value in 1 or 2 lines preferably without javascript?


Solution

  • You can set the attribute value using t-att-value="".

    So in my case I should use this input field:

    <input type="value" name="partner_id" t-att-value="user_id.partner_id.id"/>
    

    Which does the same as the given example with the <p> and javascript.