İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
4213 Görünümler

Hi!

I am trying to add a checkbox in our website represented by a boolean field in the backend.  The checkbox appears on the website checked if True and not checked if False in the backend.  However when you toggle it on the website, the new value is not recorded in the backed.  What should I do to immediately write the True/False  value in the backend field?


t-att-checked="'checked' if order.backendfield == True else False"
t-if="not 'checked'" t-set="checkboxname" t-value="False"/>

t-att-checked="'checked' if order. backendfield  == True else False"
t-if="'checked'" t-set="checkboxname" t-value="True"/>

I have tried many variations of the above code on the website view but only toggling on the backend changes the checkbox in the front end but not vice versa.  

Using odoo 14

Avatar
Vazgeç

Hi Julio, I too would like to know the solution to adding a boolean field in the My Details page on the website. I have been able to change the value, but not with a nice checkbox, rather defining the boolean input type...

<div t-attf-class="form-group #{error.get('backend_boolean') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="name">Backend Boolean?</label>
<input type="boolean" name="backend_boolean"
t-attf-class="form-control #{error.get('backend_boolean') and 'is-invalid' or ''}"
t-att-value="backend_boolean or partner.backend_boolean"/>
</div>

En İyi Yanıt

Hi,

Change the else False to else None, and you don't have to give True explicitly.

-> t-att-checked="'checked' if order.backendfield else None"

Try giving the code mentioned above.

Regards.


Avatar
Vazgeç
Üretici En İyi Yanıt

Thank you Anthony but I was not able to use your code to change the value in the backend.  I am still struggling with this idea.

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
4
Ağu 23
14829
2
May 25
603
1
Ara 24
2026
3
Oca 25
14399
1
Haz 24
4190