Recently I needed to fix a SugarCRM 7 view that had been customised/extended in JavaScript and accidentally broken. It turned out that the “events” object had been overridden instead of extended, and the view had lost some functionality.
Extending Methods in Views
I found plenty of information on how to extend views’ methods – see Extending View JavaScript in SugarCRM 7 for instance – but nobody explained how to extend a view’s objects.
Extending Objects in Custom Views
In a nutshell you have to use the _.extend()
method to append your new object to the existing one. In my case I need to extend the “events” object and so I had to extend the App.view.views.BaseRecordView.prototype.events
object like so:
({
extendsFrom: 'RecordView',
events: _.extend({
"change [name='element_name']": "customMethod",
"change [name='another_element']": "anotherMethod"
}, App.view.views.BaseRecordView.prototype.events),
})