Course Content

Expand All

Buttons Conditional Hiding

It is common to show a button only when certain conditions are verified.

To do this you need to assign a CSS class (the name it’s your own choice) to the button.

The CSS class will provide an easy way to select via jQuery the button and then disable it.

The code to hide a button must be executed when the formi s loaded, so we must use the Script area in the Form Template configuration menù.

EXAMPLE 1: Hide Operation button if it is already in the Closed state

In the following example you want to hide the Close Operation and Send Report button (Example 2 section OnClick Custom) if the ticket is already in a closed state.

Step 1: We assign a CSS class to the button from the button configuration screen.

Step 2: Go to the Form Template configuration screen, expand the Scripting Script area by clicking on the </> icon.

And insert the following code:

// $js is a string that contains JavaScript code
$js = "";
// if status is closed
if (Deep::registry('current_model_instance')->getStatus() == 3)
    //add to JavaScript string the jQuery code tu hide the button
    //note the css class defined in step1 is used in selection
    $js .= "jQuery('.btn-close').hide();";
//return JavaScript code
return $js;