Question

"Enabled" button, depending on record ?

Hi,

 

I added some buttons in my custom page, and it works fine. I want now to set the "Enabled" attribute of these buttons depending on my record.

I tried something like that:

 

canClickButton: function() {
	var param = this.get("MyParam");
	if (param) {
		var canClick = (param.value == "e9627fee-...") || (param.value == "3d3263e4-6...");
		console.log("CanClick: " + canClick);
		return canClick;
	}
	else {
		return false;
	}
}

When I try with differents records, "canClick" gets the correct value, but my button is always disabled.

Also, when I replace this function body with "return true", it works...

I don't really understand what is the problem here. :(

 

Thanks !

Like 0

Like

8 comments

Dear Jean,

Please, write here the exact code you are using:

1. Code for the button in the diff block

2. Code for the function that makes button enabled in the methods block.

Thanks for your help Peter.

Here is my code:

methods: {
	canClick: function() {
		var status = this.get("Status");
		if (status) {
			var canClick1 = (status.value == "e9627fee-15d5-4e16-8eac-36d842b03bee") || (status.value == "3d3263e4-6f25-45b1-9b41-392feb5c0c24");
			console.log("canClick: " + canClick1);
			return canClick1;
		}
		else {
			return false;
		}
	},
	actionButton: function() {
		this.showInformationDialog("Hi");
	},
	getActions: function() {
		var actionMenuItems = this.callParent(arguments);
		actionMenuItems.addItem(this.getButtonMenuItem({
			Type: "Terrasoft.MenuSeparator",
			Caption: ""
		}));
		actionMenuItems.addItem(this.getButtonMenuItem({
			"Caption": this.get("Resources.Strings.MyActionButton"),
			"Tag": "actionButton",
			"Enabled": {"bindTo": "canClick"}
		}));
		return actionMenuItems;
	}
}

 

Have you tried to click "Code validation" button when editing a schema? Your code fails validation check.

"canClick = (" - why you are using for variable the same name as for the function and omit "var" keyword?

Well I am sorry, I just noticed I failed at writing this post. I updated my last comment.

You still returning canClick. You need return canClick1

My bad, I am really sorry to ask for help and cannot even write correctly my post ... canClick1 is the value returned in my code, a boolean.

After many tries, I finnaly understood what was the main problem.

The "enabled" attribute is set the first time my function "canClick" is called. But the first time, my attribute "status" isn't initialized, "canClick" returns false (I can see that by adding a console.log before returning false), and my button is blocked.

After my entity is initialized, "canClick" is called again and returns true, but the "Enabled" attribute doesn't update, my button remains disabled ...

Is there any way to fix that ?

 

Thanks

Dear Jean

As soon as your function returns true the button will be enabled. So there is a mistake in your code. Because you have changed it few times there is possibility of mistake in other places. You can save all the code from your schema in a text file and attach it here so I could check it for you

Show all comments