October CMS resources and help articles

Simple and to the point. Optimized by the community.

Hide/show relation manager buttons

8
by larryb, last modified on August 12th, 2019

Would you prefer to hide the various buttons for your relation manager views? For example, unlink/delete buttons are visible, but disabled, unless you select a record.

If you want to override this behavior, create a partials with the name _relation_button_action.htm inside your controllers folder (i.e. Author\Plugin\Controllers\Controller), where _action equals the button you want to override. For example, if you wanted to override the delete button you would create authour/plugin/controllers/controller/_relation_button_delete.htm. The code for the partial can be copied from modules/backend/behaviors/relationcontroller/_button_action.htm or completely customized at this point.

The key lines determining the buttons behavior are:

disabled="disabled"
data-trigger-action="enable"
data-trigger="#<?= $this->relationGetId('view') ?> .control-list input[type=checkbox]"
data-trigger-condition="checked"

We will go over each of these lines below:

  1. disabled="disabled" This should be self explanatory, but this line disables the button. We will remove this line because we want our button enabled, but hidden when a record(s) is selected.
  2. data-trigger-action="enable" This line tells the framework what to do with this element. In this case, it will enable the field. We want to change this line to data-trigger-action="show".
  3. data-trigger="#<?= $this->relationGetId('view') ?> .control-list input[type=checkbox]" This line targets the checkboxes in the list view. Do not modify this line.
  4. data-trigger-condition="checked" This line tells the framework what condition to look for. Do not change this line.

Your final button partial should look something like this:

<button
        class="btn btn-sm btn-secondary oc-icon-random"
        onclick="$(this).data('request-data', {
            checked: $('#<?= $this->relationGetId('view') ?> .control-list').listWidget('getChecked')
        })"
        data-handler="onRelationButtonMove"
        data-control="popup"
        data-size="large"
        data-request-success="$.oc.relationBehavior.changed('<?= e($this->vars['relationField']) ?>', 'moved')"
        data-trigger-action="show"
        data-trigger="#<?= $this->relationGetId('view') ?> .control-list input[type=checkbox]"
        data-trigger-condition="checked"
        data-stripe-load-indicator>
        Move user(s)
</button>

Note: This functionality is not explicity documented. However, you should be able to infer this from looking at the Backend Form Trigger Event Docs.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?