Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
1891 Visualizzazioni

In odoo 17. 

I have the following problem: 

I have a component (MYCOMPONENT), which has in its .xml a Notebook (WEB component) with only 2 pages. In the "onMounted" of MYCOMPONENTE i need to make visual modifications to elements that are within each of the Notebook pages, since that information is dynamic in terms of styles and visual details.

It turns out that when I open my page in the browser with one of the Notebook pages displayed or active, everything is fine, but when I start interacting with this interface (Notebook pages) the information that I updated in "onMounted" is no longer there. The pages are as originally planned in the .xml, and I am referring to the visual information, as well as what I added from the UI.


thank

Avatar
Abbandona
Risposta migliore

In Odoo 17, which uses the OWL (Odoo Web Library) framework, the issue you're encountering seems related to the lifecycle of the OWL components, specifically with the interaction between the onMounted hook and how the Notebook component re-renders its pages.


When you interact with a Notebook (such as switching tabs), OWL might re-render the content inside the Notebook, which can reset the DOM modifications you made in the onMounted hook. Since OWL's rendering process is reactive, it can re-apply the original state as defined in your component's template when the component re-renders.


Solution

To ensure that your dynamic styles and modifications persist even after interacting with the Notebook, you need to use a combination of OWL's lifecycle hooks and event listeners to apply these changes every time the Notebook re-renders or changes pages.


Here’s how you can approach it:


1. Use the onPatched Lifecycle Hook

The onPatched lifecycle hook can be used to reapply the modifications whenever the component is re-rendered.


2. Handle Notebook Tab Change

You should also ensure that your styles are reapplied when the user switches between Notebook tabs. You can do this by adding an event listener for the Notebook tab changes.


3. Ensure that the CSS selectors you use to target elements inside the Notebook pages are precise and correctly reference the elements you want to modify. The this.el.querySelector method searches within the component’s root element, so make sure the selectors match the structure of your Notebook component.

Avatar
Abbandona
Autore

thank for the answer, i wil testing notebook tab change event

Post correlati Risposte Visualizzazioni Attività
2
lug 25
1673
2
lug 25
1808
1
mar 25
1340
5
mar 25
3364
1
feb 25
1634