Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
12 Views

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.

Avatar
Discard

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");
  ​}

});

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!