Skip to content
Advertisement

Get access to other elements from widget inside form view

Odoo 13.

I got two float fields: time_given and timer.

I have created a widget for ‘timer’ field. My widget works as real-time clock or some sort of timer. The problem I have encountered is that I want to change the style of ‘time_given’ field based on the following condition:

((time_given – timer) <= 30 sec) i.e less than 30 seconds left

To change the style of the field the widget attached to is pretty easy, but I am not sure hot to get access to other field elements in the form view I need and make some visual manipulations with them if needed.

I was able to get access to other field elements, change their style and add some text but the it is not a proper way.

this.__parentedParent.__parentedChildren

I get array of objects, then I loop through it and look for the field needed. After I found my target field element I am able to play with it. For example:

$field_name.addClass('text-danger')

The way above works pretty fine but again as I said before, this is definitely not a proper way.

I was trying to find the right field element and add class to it by the following way:

$("[name='field_name']").addClass('text-danger')

It found the element, but did not add the class ‘text-danger’.

I was trying my best by googling and reading the source code, but failed.

enter image description here

Advertisement

Answer

I have managed to solve this issue. Just used core.bus.trigger method mentioned in the official documentation.

P.s. In case if you are still interested how I did this in more details, just let me know in the comments section below.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement