From b42e9cc686e7d3ccf82cd091a5dc24028fff8a2b Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 14 Dec 2023 13:56:03 +0100 Subject: [PATCH] [FIX] website: restore default checked value for form checkboxes Before this commit and since PR [1], the default "checked" value set on checkboxes field on the form snippet were lost once the page is saved. This is because [1] changed the rendering engine of qweb templates from our own qweb js rendering code to owl templates rendering. By doing so, `t-att-checked="'checked'"` would toggle the "internal" checkbox checked value but would not add the checked attribute on the element. It's a deliberate choice made in owl. As the checked attributed does not mean the same as the internal checked value, it makes sense. Indeed, the checked attribute is about the default value of the checkbox while the checked internal value is about the current checked state of the checkbox. In React, for instance, the same behavior can be seen. And if one wants to really set the checked attribute, they got to go with `defaultChecked`. Same apply with `value`. Maybe owl will implement the same `defaultXXX` behavior in the future as it's something that was already discussed on their side. Step to reproduce: - Drag & drop a form in the website builder - Add a new custom field and select "Multiple Checkboxes" type - Set one of the checkbox checked by default - It is visually checked, but the attribute is not set - Save the page -> The checkbox is back to unset state since the attribute was not set [1]: https://github.com/odoo/odoo/pull/130467 opw-3607795 closes odoo/odoo#146328 Signed-off-by: Romain Derie (rde) --- addons/website/static/src/xml/website_form_editor.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website/static/src/xml/website_form_editor.xml b/addons/website/static/src/xml/website_form_editor.xml index 3cc82cafb5a..8d0e34bcdd9 100644 --- a/addons/website/static/src/xml/website_form_editor.xml +++ b/addons/website/static/src/xml/website_form_editor.xml @@ -332,7 +332,7 @@ class="s_website_form_input form-check-input" t-att-id="recordId" t-att-name="field.name" - t-att-checked="record.selected and 'checked' or None" + t-att="{checked: record.selected and 'checked' or None}" t-att-value="record.id" t-att-required="field.required || field.modelRequired || None" />