AnsweredAssumed Answered

JS How to run code on change relationship?

Question asked by Timothy Gentle on Jan 12, 2017

I'm trying to detect and run code when I change the associated account on a module. It's not important to me which modules are in question as I'll need this for all modules where you can select either an account or a contact.

 

The end goal is to display an alert if you select an account/contact where an alert is set, but for now, I'm trying to simply fire a function when a relationship field is set.

 

I'm currently trying to use backbone to detect something by sticking this into the record.js file in accounts:

 

({
extendsFrom: 'AccountsRecordView',
initialize:function(options){
this._super("initialize",[options]);
this.context.on('app:view:change',this.handlemodchg);
console.log(this);
},
handlemodchg:_.throttle(function(){
console.log("cheeseburgers");
},
1000,
{leading:false})
})

If I can catch all relate field changes, or even just any field change, I can then carry on to calculate which field changed and move from there.

 

Any help on this would be most appreciated.

Outcomes