Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Disable Copy Paste option for particular component

Avatar

Level 1

I am using AEM 6.5,

Let's imagine I have AEM components "Component A" 

sam2k8_0-1686666720052.png

 

I want to disable Copy, Cut and Paste option for this particular component.

How can I achieve that programmatically?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

This can be achieved by using cq:actions, please find more here: https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/components-basic...

For example:

<jcr:root xmlns:cq="https://www.day.com/jcr/cq/1.0" xmlns:jcr="https://www.jcp.org/jcr/1.0"
    cq:actions="[edit,delete,insert]"
    cq:layout="editbar"
    jcr:primaryType="cq:EditConfig"/>

Config applied:

Esteban666_0-1686667388656.png

Result:

Esteban666_1-1686667406111.png

 

 



Esteban Bustamante

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

This can be achieved by using cq:actions, please find more here: https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/components-basic...

For example:

<jcr:root xmlns:cq="https://www.day.com/jcr/cq/1.0" xmlns:jcr="https://www.jcp.org/jcr/1.0"
    cq:actions="[edit,delete,insert]"
    cq:layout="editbar"
    jcr:primaryType="cq:EditConfig"/>

Config applied:

Esteban666_0-1686667388656.png

Result:

Esteban666_1-1686667406111.png

 

 



Esteban Bustamante

Avatar

Community Advisor

@sam2k8  if you are looking for a custom solution follow below js code

(function ($, ns, channel, window, undefined) {
// Function to disable copy-paste for the component
function disableCopyPaste() {
// Disable copy-paste on component's elements
$('.your-component-class').on('copy paste', function (event) {
event.preventDefault();
return false;
});
}

// Wait for the foundation-contentloaded event to ensure the component has loaded
channel.on('foundation-contentloaded', function (event) {
var $component = $('.your-component-class');

if ($component.length) {
disableCopyPaste();
}
});
})(jQuery, Granite.author, jQuery(document), this);

Replace 'your-component-class' with the CSS class name of your component.

 

If you are looking for OOTB feature as suggested by @EstebanBustamante  you can edit it in the cq:editConfig

Avatar

Employee Advisor

Hi,

 

To programmatically disable Copy, Cut, and Paste options for a specific component in AEM 6.5:

  1. Create a custom context-aware configuration under the component's folder.
  2. Add a property named cq:disableAction with a value of copy cut paste to the cq:actions node.
  3. Replicate the configuration to necessary language folders if applicable.
  4. After making these changes, the options will be disabled for the component in the AEM authoring interface.