owl-handler-not-a-function (OWL003)#

A t-on-* handler in an OWL template is a statement, not a function.

Applies to Odoo 16.0 and later.

What it does#

Reports t-on-* attributes whose value assigns (state.open = true, state.count++) instead of naming a function (onClick, props.onSelect, () => this.onClick(line)).

Why is this bad?#

OWL 2 evaluates the value when the template renders and calls the result on the event. An assignment runs at every render, and the click then fails with “Invalid handler (expected a function, …)”. OWL 1 ran the expression on the event; templates ported from it keep that form.

A call (onClick(line)) is not reported: a method that returns the handler (protectedClick(handler)) is a common pattern.

Example#

<button t-on-click="state.open = !state.open">Toggle</button>

Use instead:

<button t-on-click="() => this.state.open = !this.state.open">Toggle</button>