Question

Error Button enable

 I need it to be available only to men when opening a contact. At initialization, there are no rights to the scope. What should be done?

define("ContactPageV2", [], function() {
	return {
		entitySchemaName: "Contact",
		attributes: {
            /* The attribute for storing the availability status of the button. */
            "ButtonEnabled": {
                "dataValueType": Terrasoft.DataValueType.BOOLEAN,
                "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                "value": true
        	}
		},
		messages: {
			"NewPageInfo": {
				mode: Terrasoft.MessageMode.PTP,
				direction: Terrasoft.MessageDirectionType.SUBSCRIBE
			}
		},
		methods: {
			onEntityInitialized: function() {
				this.callParent(arguments);
				this.setButtonEnabled();
				this.sandbox.subscribe("NewPageInfo", function() {
					return this;
				}, this, ["SectionModuleV2_ContactSectionV2"]);
			},
			onPageClick: function() {
				this.showInformationDialog("dwdwdwdwdwdwdw");
			},
			setButtonEnabled: function() {
                if (this.get("Gender").value == "eeac42ee-65b6-df11-831a-001d60e938c6") {
					return("ButtonEnabled", true);        
                }
                else {
					return("ButtonEnabled", false);
                }
            }
		},
		diff: [ {
				"operation": "insert",
				"parentName": "LeftContainer",
				"propertyName": "items",
				"name": "NewButton",
				"values": {
					"afterrerender":{bindTo: "setButtonEnabled"},
					"afterrender":{bindTo:"setButtonEnabled"},
					"itemType": Terrasoft.ViewItemType.BUTTON,
   		            "caption": {bindTo: "Resources.Strings.NewButtonCaption"},
  	              	"classes": {"textClass": "actions-button-margin-right"},
					"click": {bindTo: "onPageClick"},
					"style": Terrasoft.controls.ButtonEnums.style.BLUE,
					"enabled": {bindTo: "ButtonEnabled"},
				}
        }
	]/**SCHEMA_DIFF*/
	};
});
 
define("ContactSectionV2", [], function() {
	return {
		entitySchemaName: "Contact",
		messages: {
			"NewPageInfo": {
				mode: Terrasoft.MessageMode.PTP,
				direction: Terrasoft.MessageDirectionType.PUBLISH
			}
		},
		methods: {
			onSectionClick: function(){
				var pageInfo = this.sandbox.publish("NewPageInfo", null, [this.sandbox.id]);
				pageInfo.onPageClick();
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "insert",
				"parentName": "CombinedModeActionButtonsCardLeftContainer",
				"propertyName": "items",
				"name": "NewButton",
				"values": {
					"itemType": Terrasoft.ViewItemType.BUTTON,
                    "caption": {bindTo: "Resources.Strings.NewButtonCaption"},
                    "classes": {"textClass": "actions-button-margin-right"},
					"click": {bindTo: "onSectionClick"},
					"style": Terrasoft.controls.ButtonEnums.style.RED
				}
			}
		]/**SCHEMA_DIFF*/
	};
});
Like 0

Like

2 comments

 

Erlan Ibraev,

 

Hello,

 

This error message indicates that when the setButtonEnabled method was executing this part of code returned undefined:

 

this.get("Gender")

 

and since it returned undefined and the complete code is:

 

this.get("Gender").value

 

it tried to read value from undefined and returned an error. You need to add additional check in the code like:

setButtonEnabled: function() {
                if (this.get("Gender") && this.get("Gender").value == "eeac42ee-65b6-df11-831a-001d60e938c6") {
					return("ButtonEnabled", true); 

In such case the error won't occur and the page will be loaded.

Show all comments