How can do I add an alert whenever a relate field changes.. That when cancelled the data will not change.
How can do I add an alert whenever a relate field changes.. That when cancelled the data will not change.
If I understand correctly you want to catch the cancel event and warn the user that they changed a relate field and the change will not be saved.
I would customize the controller for the record view, capture the fields that changed, and use a "confirmation" type alert to warn the user. If the user confirms the cancel, proceed with the parent cancel action, else do nothing and wait for the user to choose Save, or Cancel again.
The controller for the record view is clients/base/views/record/record.js
there you can see the handleCancel function, which reverts the changed attributes.
You can follow the sidecar extension model (there is an old, but still valid, example here: https://sugarclub.sugarcrm.com/dev-club/b/dev-blog/posts/extending-sugar-7-1-5-record-view )
and extend the handleCancel to check the changed attributes before doing anything else.
Object.keys(this.model.changed.Attributes(this.model.getSynced()));
will give you a list of changed fields, see if the one you want to check is one of them, and if so use a SugarAlert with alert level "confirmation" to warn the user.
on confirm, you can call the parent handleCancel to continue with the standard cancel, if not then do nothing.
The alert will give you two options "Cancel" and "Confirm", which in this case may create confusion since in this case the "Cancel" means cancel the Cancel action rather than proceed with the Cancel action... but you can change the action names for the alert. See:
sugarclub.sugarcrm.com/.../how-to-modify-aler-box-button-label-for-particular-module
FrancescaS