Posted by : Ajay Kumar Wednesday, 17 February 2016

Let me explain how to disable button action dynamically thorough controller(ex.record.js) and when our condition meets.

I am creating one button as "Check Button" for Accounts module.

So i am copying record.php from /modules/Accounts/clients/base/views/record/record.php to
custom/modules/Accounts/clients/base/views/record/record.php
array(
'type'=>'rowaction',
'event'=>'button:check_button:click',
'name'=>'check_button',
'label'=>'LBL_CHECK_BUTTON_LABEL',
'acl_action'=>'view',
),
view raw record.php hosted with ❤ by GitHub
Above is the our custom button array to add to Accounts module.I Assume you know how to add button array in record.php
To Add label for custom button , I am creating new file in below path and adding content to that.
/custom/Extension/modules/Accounts/Ext/Language/en_us.check_button.php
<?php
/*Setting Label for button
* AjayKumar
* custom/Extension/modules/Accounts/Ext/Language/en_us.check_button.php
*/
$mod_strings['LBL_CHECK_BUTTON_LABEL']='Checking router record';

Now button is ready.

Now we need to button action in controller file.I know you got what i mean,yes we need to add action for check_button in record.js.

Below is our scenario,

If Account type is customer ,then we should not allow user to edit that record.So we are going to disable "edit" and "check" button when condition meets.

({
/*Disabling button ,condition based or dynamically on RecordView.
* AjayKumar
* custom/modules/Accounts/clients/base/views/record/reord.js
*/
extendsFrom:'RecordView',
initialize:function(options){
this._super('initialize',[options]);
this.on('render',this.makedisableButton,this);
},
makedisableButton:function(){
var accountType,editButton,checkButton;
editButton=this.getField('edit_button'); // passing argument as name of button
checkButton=this.getField('check_button');
AccountType=this.model.get('account_type');
if (editButton && checkButton && _.isEqual(AccountType,'Customer')) {
editButton.setDisabled(true);
checkButton.setDisabled(true);
}
},
})
view raw record.js hosted with ❤ by GitHub

Thats it. Make a repair and rebuild.










- Copyright © 2025 SugarCRM Blog - Ajay Kumar - Powered by Blogger - Designed by Ajay Kumar -