[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) <rde@odoo.com>
This commit is contained in:
Romain Derie
2023-12-15 11:40:44 +00:00
parent e5097a183a
commit b42e9cc686
@@ -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"
/>