Hey Cyllo folks, anyone know the ins and outs of widget lifecycle methods? I'm trying to figure out the best way to handle something and could use some pointers.
Welcome!
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
This question has been flagged
Here's a breakdown of the Odoo widget lifecycle methods and how to use them effectively. This example demonstrates the typical flow of each method. These methods allow full control over your widget's behavior from creation to destruction.
init()
Called when the widget is created.
willStart()
Prepares async data before rendering (returns a Promise).
start()
Runs after the DOM is ready (use for DOM manipulation or event binding).
destroy()
Cleans up resources when the widget is removed.
import publicWidget from "@web/legacy/js/public/public_widget";
publicWidget.registry.LifecycleDemo = publicWidget.Widget.extend({
selector: '#demo',
init() {
this._super(...arguments);
console.log("init");
},
willStart() {
console.log("willStart");
return Promise.resolve();
},
start() {
console.log("start");
},
destroy() {
console.log("destroy");
}
});