This question has been flagged
1 Reply
5283 Views

I have a  button(say X) to display a html widget, This html widget is in one2many relation with  the   main model Y , The button X makes a call to the write method 


In a form for model Y, I click create and click the button X before hitting Save button of Y 

this results in the following warning 


The record has been modified, your changes will be discarded. Are you sure you want to leave this page ?


can anyone please tell me how to avoid this warning 

Avatar
Discard
Best Answer

To avoid that behavior I only know how to do it by going into the JS way to avoid the default behavior that makes the record saves and validation when leaving the current record with changes

But that it's the hard way because you need to do everything by yourself and that way you need to know what are you doing and how to do it. 

Take this as an starting point code, it contains 3 ways to get it:

    var o2m_list_view_ext = false;
    FieldOne2Many.include({
        init: function() {
            this._super.apply(this, arguments);
            if(o2m_list_view_ext == false){
                o2m_list_view_ext = true;
                var One2ManyListView = this.x2many_views.list;
                One2ManyListView.include({
                    do_button_action: function (name, id, callback) {
                        var self = this;
                        var action = _.detect(this.columns, function (field) {
                            return field.name === name;
                        });
                        if(action.widget != undefined && action.widget == 'your_custom_button_widget'){
                            // call your js code here
                            // ...
                            // or 
                            // call the normal button action without restrictions like:
                            // ...
                            // self.handle_button(name, id, callback);
                            // or if the view need to be reloaded:
                            // ...
                            // self.handle_button(name, id, function(){
                            //     self.x2m.view.reload();
                            // });
                        } else {
                            this._super(name, id, callback);
                        }
                    }
                });
            }
        }
    });

After that you only need to define a button using the expected widget

Hope this helps

Avatar
Discard