How can I get information form an account page via the [Addresses] detail? For example, I need to call a function or retrieve information from a field (e.g., name) or learn the field status (e.g., enabled)
Question
How can I get information form an account page via the [Addresses] detail? For example, I need to call a function or retrieve information from a field (e.g., name) or learn the field status (e.g., enabled).
Answer
To connect a detail with a page, use the message mechanism. You can use base messages or create custom ones (you will have to create a replacing module in this case).
For example, you can execute a ReloadDetail message subscription in the implementation of the init() method of the detail code as follows:
this.methods.init = function() { ... this.sandbox.subscribe("ReloadDetail", function(customArgs) { // executing actions with function arguments }, [this.sandbox.id]); }
Further, you can publish the message in the parent page code by an action:
this.methods.myAction = function() { Terrasoft.each(this.entitySchemaInfo.details, function(detailInfo) { if (detailInfo.name === "addresses") { sandbox.publish("ReloadDetail", this, [detailInfo.moduleId]); } }, this); }
Passing this as a parameter when publishing enables accessing the page object in a detail as well as accessing all its attributes and methods, etc. – this object will be passed in the customArgs parameter. You can pass a set of only the needed data instead of this.
You do not need to create ReloadDetail, it is already contained in the base modules of pages and details.
We recommend receiving the values of needed conditions before this moment, since after you perform getCustomItemView(), the control will be passed over to the base detail module (DetailModule), where the model is linked to the view and detail rendering is performed.