This topic is locked

how to hide a custom button in a row based on a value in that row

11/18/2020 11:19:33 PM
PHPRunner General questions
W
wfcentral author

I have a button called with "Certificate" on it. Clicking this button pop-up a window that loads an external page with a certificate for the student to print. On that same row I have a pass/fail field called "score". The rows are edited using inline edit. My client said that if the student failed the course then they should not be able to access the certificate button.
I've tried several says to hide or disable the custom button based on the value in this row field, but it is not working.
Can anyone give me a hint on how to pull this off?

D
david22585 11/19/2020



I have a button called with "Certificate" on it. Clicking this button pop-up a window that loads an external page with a certificate for the student to print. On that same row I have a pass/fail field called "score". The rows are edited using inline edit. My client said that if the student failed the course then they should not be able to access the certificate button.
I've tried several says to hide or disable the custom button based on the value in this row field, but it is not working.
Can anyone give me a hint on how to pull this off?


Is the score for a pass/fail a boolen like 1 or 0, or a word like Pass/Fail, or a numeric value like <70 fail >70 pass?
Go to events -> List Page After Record Process:

if ($data["score"] >= '70'){

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

} else {

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

}


if ($data["score"] == '1'){

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

} else {

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

}


if ($data["score"] == 'Pass'){

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

} else {

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

}


The certificate is the name of the button. You can rename it on the designer page by clicking on the custom button, on the right where it says Item ID, click rename and make it certificate. Or use whatever that says in the code above.

W
wfcentral author 11/19/2020

that sounds like what I'm looking for - but would it work on a row by row basis? below is a screenshot of what I'm dealing with. I actually have several columns that can marked as pass/fail (Level I, II, III) and if there is a "Fail" in any of those values then the button for that row "certificate" should not be available.

Admin 11/19/2020

Yes, it will work this way. Just in case here is the link to documentation:

https://xlinesoft.com/phprunner/docs/hideitem.htm

D
david22585 11/19/2020



that sounds like what I'm looking for - but would it work on a row by row basis? below is a screenshot of what I'm dealing with. I actually have several columns that can marked as pass/fail (Level I, II, III) and if there is a "Fail" in any of those values then the button for that row "certificate" should not be available.



Yes, do it like this:



if ($data["level1score"] == 'Fail'){

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

} else if ($data["level2score"] == 'Fail'){

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

} else if ($data["level3score"] == 'Fail'){

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

} else {

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

}
W
wfcentral author 11/19/2020

placing this code on

events -> List Page After Record Process:
works - however you only see the button hidden with the page first loads (and score is set to false) or after reloading the page (after setting a score to false).
the button does not disappear after saving the row using inline edit.
I'm assuming I will need to use the javascript api on the actual field itself. So, I tried going to the level I field (which is a dropdown) and adding the field event
event: change
pageObj.toggleItem("Certificate_Button", false, row.recordId() );
which I assumed would hide the button anytime that dropdown was changed.
Once I got that working I was going to wrap it in the condition that the value be "Fail" (then the button would hide).
However, I must be doing something wrong because I can't get the button to hide using javascript. I putting it on the "client before" field events on View Page (even though this control is really on a list page as a child table).
Basically - the button HAS to hide immediately when the user edits and places a FAIL in there so they cannot access the certificate button. Right now without using javascript the user can still access the button until they enter a FAIL AND reload the entire page AND I don't know how to get the javascript to work so any tips would be greatly appreciated.

W
wfcentral author 11/20/2020

I must be doing something wrong and/or not understanding how this works. I just added some simple javascript to the dropdown for level1 on a row and I expect to see the javascript popup when I change that dropdown using inline edit for that row. However, nothing is happening. If I can figure out why this doesn't work then I can move on to the more advanced task of making it hide the certificate button when the user selects FAIL on the dropdown.

Admin 11/20/2020

List Page: After Record Processed event is executed on the page load. It doesn't execute after inline add or edit.
What you can do is to show or hide the respective button manually using AfterInlineEdit event:

https://xlinesoft.com/phprunner/docs/how_to_control_inline_add_edit_functionality_from_script.htm

Section 'How to execute JavaScript code after the Inline Add or Edit'

W
wfcentral author 11/20/2020



List Page: After Record Processed event is executed on the page load. It doesn't execute after inline add or edit.
What you can do is to show or hide the respective button manually using AfterInlineEdit event:

https://xlinesoft.com/phprunner/docs/how_to_control_inline_add_edit_functionality_from_script.htm

Section 'How to execute JavaScript code after the Inline Add or Edit'


that worked perfectly - thanks!

W
wfcentral author 11/20/2020



that worked perfectly - thanks!


I tried adding both (for add and edit) and the add version is not working...
is it not possible to put this on the Javascript: onload event section?
if( !pageObj.myAfterInline ) {

this.on('afterInlineEdit', function( fieldsData ) {

pageObj.reload({});

} );

pageObj.myAfterInline = true;

}
if( !pageObj.myAfterInline ) {

this.on('afterInlineAdd', function( fieldsData ) {

pageObj.reload({});

} );

pageObj.myAfterInline = true;

}

W
wfcentral author 11/20/2020

oops
I changed it to this and it works now...
if( !pageObj.myAfterInline1 ) {

this.on('afterInlineEdit', function( fieldsData ) {

pageObj.reload({});

} );

pageObj.myAfterInline1 = true;

}
if( !pageObj.myAfterInline2 ) {

this.on('afterInlineAdd', function( fieldsData ) {

pageObj.reload({});

} );

pageObj.myAfterInline2 = true;

}