简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM