0
votes

i added a checkbox on product page When (checkbox_customtext) field is TRUE a (customtext) field should appear on the site When an False field should disappear I wrote the code but does not work Please help me solve the problem py xml files

<odoo>
<template id="website_insert_customtext" inherit_id="website_sale.address">
    <xpath expr="//div[@id='div_phone']" position="after">


                        <!--hier is not working-->
            <figure t-foreach="product_template" t-as="o" t-if="o.checkbox_customtext == True"  class="snip1533">

                <div t-attf-class="form-group #{error.get('customtext') and 'has-error' or ''} col-md-6"
                     id="div_custom_text">
                    <label class="control-label" for="customtext">Custom Text ( Only For Tactical vest )</label>
                    <input name="customtext" class="form-control"
                           t-att-value="'customtext' in checkout and checkout['customtext']"/>
                </div>



            </figure>
    </xpath>
</template>

by .py from odoo import models, fields

class ProductTemplate(models.Model): _inherit = 'product.template'

checkbox_customtext = fields.Boolean('Add Custom field', default=True, )

class ResPartner(models.Model): _inherit = 'sale.order'

customtext = fields.Char('Custom Text')
1

1 Answers

0
votes

You can do it without using template. Just add to your customtext field in xml attrs="{'invisible': #your_domain}" and it will do the job.

<field name="customtext" attrs="{'invisible':[('checkbox_customtext', '=', False)]}"/>