Disable a button based on CONDITION in Odoo?

倖福魔咒の 提交于 2020-04-11 13:55:36

问题


How can i add disabled class with attributes to field based on CONDITION?

I tried as below methods,

1)

<t t-if="product.qty_available &lt;= 0">
    <attribute name="class">btn btn-primary btn-lg mt8 js_check_product a-submit disabled</attribute>
</t>

2)

<attribute name="class" t-if="product.qty_available &gt; 0">btn btn-primary btn-lg mt8 js_check_product a-submit disabled</attribute>

3)

<attribute name="class" >product.qty_available &gt; 0 and 'btn btn-primary btn-lg mt8 js_check_product a-submit' or 'btn btn-primary btn-lg mt8 js_check_product a-submit disabled'</attribute>

Can some one helping me to achieve this?


回答1:


try this one:

<attribute name="t-att-disabled" > "1 if product.qty_available else 0" </attribute>



回答2:


Did with position="replace"

<xpath expr="//a[@id='add_to_cart']" position="replace">
      <a id="add_to_cart" t-attf-class="btn btn-primary btn-lg mt8 js_check_product a-submit #{product.qty_available &lt;= 0 and 'disabled'}" href="#" >Add to Cart</a>
  </xpath> 


来源:https://stackoverflow.com/questions/37477673/disable-a-button-based-on-condition-in-odoo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!