This topic is locked
[SOLVED]

 DIsable "inserted button" based on field's value on Grid

5/4/2019 1:18:26 PM
PHPRunner General questions
A
acpan author

Hi,
I have a grid table with a list of customers, and inserted a custom button on each row to send email reminder to the customer when its account balane (another field) is below certain value.
I want to do it using grid table and custom button instead of running a background job so that i can choose to send reminder only when needed.
Here's the Grid Layout:
Cust_ID | Cust_Name | Email | Account_Balance | EMail_Custom_Button
I have no issue with the custom button codes (Client Before, Server and Client After).
My issue is i want the Email button to be disabled if the account_balance value is above 120 on the grid, when the page is loaded.
What i did:
On my Grid's Javascript on load:
var id = "Send_Email_Reminder";

var button = $("[id^=" + id + "]");

Runner.addDisabledClass(button);
This disables all the buttons, i need to be able to check the value of Account_Balance and turn on(Enable) and off(Disable) the button.
Had read the online manual and other topics but can't get it work, any pointers will be grateful.
ACP

admin 5/6/2019

I would rather suggest hiding the button instead of disabling it, it might be easier. Check 'How to hide a custom button?' section at https://xlinesoft.com/blog/2019/03/05/page-designer-frequently-asked-questions-answered/

A
acpan author 5/6/2019



I would rather suggest hiding the button instead of disabling it, it might be easier. Check 'How to hide a custom button?' section at https://xlinesoft.com/blog/2019/03/05/page-designer-frequently-asked-questions-answered/


Hi Sergey,
Thanks, yes, this is defintely the best way! Thanks for the direction.
Just to share so it may help other:

  1. Go to PHPR Designer Page.
  2. Select the custom button inserted on the grid by clicking on it once.

    Then on the right panel, click the ? mark on the right of "item_id" to popup a note page that explains how to use the codes.
  3. Since i need to handle the custom button on the grid, i copy the following from the notes and paste to the after record processed event:

$pageObject->hideItem("email_reminder_button", $recordId);

$pageObject->showItem("email_reminder_button", $recordId);


Note: there is no need to edit anything, just copy and paste as the notes will automatically grab the right ID for you.
4. At the after record processed event, i can now conditioanlly hide and show the custom button based on the row data values:

// for troubleshooting, echo the row's data (values in the database for the row):

echo json_encode($data);
$account_balance = $data["account_balance"];
if ( $account_balance < 120 )

{

$pageObject->showItem("email_reminder_button", $recordId);

}

else

{

$pageObject->hideItem("email_reminder_button", $recordId);

}


5. That's all, the custom buttons will now show and hide based on its row values on list page.