I have added a custom button called "Confirm Audience" to a detail and it's working fine. but in the meantime, I need to disable the button once I click on it. So far I tried to disable it using an attribute, which is mentioned in this article.
https://community.creatio.com/questions/how-can-i-disable-button-once-clicked
While implementing that scenario I am facing an issue which is when we reload the page or go back and come back to the same record, the button behavior will be going back to its default behavior. If there is a way to achieve this please help me on this.
And this is how I added the button to my schema.
diff: /**SCHEMA_DIFF*/[ { "operation": "insert", "name": "ConfirmAudienceButton", "parentName": "Detail", "propertyName": "tools", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": {"bindTo": "Resources.Strings.BEACSConfirmButtonCaption"}, "click": {"bindTo": "onConfirmButtonClick"}, //method to trigger the button "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT, "visible": {"bindTo": "getIsConfirmAudienceEnabled"} } } ]/**SCHEMA_DIFF*/, methods: { onConfirmButtonClick: function() { var recordID = this.values.MasterRecordId; var confirmAudienceBoolean = this.values.MasterRecordId.BEACSConfirmAudience; var args = { sysProcessName: "BEACSProcess_1df603c", parameters: { ProcessSchemaRecordId:recordID, } }; ProcessModuleUtilities.executeProcess(args); this.set("isConfirmButtonClicked",false); }, getIsConfirmAudienceEnabled: function() { return !this.$IsGridEmpty; }, }
Like
Lakindu Yasomith,
I am sorry for assuming that the result of the click would have other visible changes in local conditions that were not mentioned.
Since now we have the only possible condition of the button - it is either clicked or not - the only solution would be adding a global boolean variable (a checkbox) to the object that would be stored in the DB.
We can imagine that the column would be UsrButtonIsClicked.
You would be able to check it using this.UsrButtonIsClicked or method to call query handler "await". Please see an example by the link below:
https://academy.creatio.com/docs/developer/front_end_development_freedo…
Note that logic of updating this value in the database as onClick is triggered would be also required.
Best Regards,
Denys
Hello Lakindu,
In your example, the attribute "IsButtonEnabled" is true when defined.
attributes: { "IsButtonEnabled": { dataValueType: Terrasoft.DataValueType.BOOLEAN, type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, value: true } }
There are some options.
1) First one is to use local conditions, already available on the page by setting the value to this attribute in the onEntityInitialized method:
methods: { onEntityInitialized: function() { this.callParent(arguments); this.setIsButtonEnabled(); }, setIsButtonEnabled: function() { if (YOUR CONDITION) { this.set("IsButtonEnabled", true); } else this.set("IsButtonEnabled", false); } },
2) If you want to make this condition global for all users - you would need to use DataBase. For example, add a new boolean column to the connected object (It is not necessary to display this column on any page, it may just exist in the background). Read and update the value to determine if the button is visible or not.
Best Regards,
Dan
Hi Denis,
I really appreciate your reply but I'm afraid you clearly didn't understand my question here. I'm asking how to disable or hide the button once the button is CLICKED. where you also mentioned "YOUR CONDITION". what I want is that "your condition" part.
Kind Regards,
Lakindu
Lakindu Yasomith,
I am sorry for assuming that the result of the click would have other visible changes in local conditions that were not mentioned.
Since now we have the only possible condition of the button - it is either clicked or not - the only solution would be adding a global boolean variable (a checkbox) to the object that would be stored in the DB.
We can imagine that the column would be UsrButtonIsClicked.
You would be able to check it using this.UsrButtonIsClicked or method to call query handler "await". Please see an example by the link below:
https://academy.creatio.com/docs/developer/front_end_development_freedo…
Note that logic of updating this value in the database as onClick is triggered would be also required.
Best Regards,
Denys