Javascript identifier for widget in Odoo

Viewed 214

If you have two widget in a view. And you do something with the first widget and you want to update (call display_field) the second widget. How to have the identifier for the second widget?

For example in the extend definition of a widget:

local.FieldNewWidget = instance.web.form.AbstractField.extend({
    init: function(parent, options) {
    },
    events: {
        'click .oe_new_input_button': 'open_new_specific_form',
    },
    start: function() {
    },
    display_field: function() {
    },
    render_value: function() {
    },
    open_new_specific_form: function(event) {
        var self = this;

        var new_action = {
            type: 'ir.actions.act_window',
            name: $(event.target).data('name'),
            res_model: $(event.target).data('data-model'),
            res_id: $(event.target).data('res-id'),
            view_mode: 'form',
            view_type: 'form',
            views: [[false, 'form']],
            target: 'new',
            context: {
            },
            flags: {'form': {'action_buttons': true}},
        }

        self.do_action(new_action, {
            on_close: function() {
                // I want to refresh (call display_field) the second widget here.
                // What is the identifier for the second widget?
            },
        });
    },
});
1 Answers

i think this will work but i don't know if it's the best solution. I think every widget knows witch view it's by using (this.view). why don't you use a special event to trigger it from one widget and listen for it in the other one.

For example Register an event listener on the widget to listen for property changing on the view:

         //in first widget register the event listener:
         this.view.on('property_name', this, this.your_method);



        // in second widget trigger the event by setting the value
        this.view.set('property_name', a_value);

i'm new to odoo javascript let me know if this works for you i think there is a better solution by using events triggering without changing properties at all.

Related