Copy the value of an Item to Clipboard in Oracle APEX

APEX does not provide an inbuilt functionality to copy the value of a page item to clipboard.

Use my plug-in Copy To Clipboard to achieve or if it has to be achieved via code please follow the below steps :-

For visible Items:

1) Create an  Item in the APEX page. (In this example the Item is P1_ITEM)

2) Create a button. (In this example the button is P1_COPY)

3) Create a Dynamic action 

        Event: Click

        Selection Type: Button

        Button: P1_COPY

4) Create a True Action

     Action: Execute JavaScript Code

     Paste the below code:       

/*to select the text field*/
$("#P1_ITEM").select();

/*to copy the text inside the text field*/ 
document.execCommand("copy");

/*to show success message (Optional)*/
apex.message.showPageSuccess('Copied to Clipboard!'); 

For hidden Items:

Step 1,2 and 3 is similar

4) Create a True Action

     Action: Execute JavaScript Code

     Paste the below code:       

/*to get the value of the hidden item*/
let item = $("#P1_ITEM");

/*to change the item type to text and select the value inside the item*/ 
item.attr("type", "text").select();

/*to copy the text inside the item*/
document.execCommand("copy");

/*to change the item type to hidden*/
item.attr("type", "hidden");

/*to show success message (Optional)*/
apex.message.showPageSuccess('Copied to Clipboard!');

For Radio Group Items:

1) Create an  Item in the APEX page. (In this example the Item is P1_RG_ITEM, Type -> Radio Group)

2) Create another  Item (In this example the Item is P1_ITEM, Type -> Hidden)

3) Create a button. (In this example the button is P1_COPY)

3) Create a Dynamic action 

        Event: Click

        Selection Type: Button

        Button: P1_COPY

4) Create a True Action

     Action: Execute JavaScript Code

     Paste the below code:  

/*to get the value of the checked Radio Group*/
let itemValue = $('input[name="P1_RG_ITEM"]:checked').val();
if(itemValue) {
    /*to store the seleted value*/
    $s('P1_ITEM',itemValue);

    /*to get the value of the hidden item*/
    let item = $("#P1_ITEM");
/*to change the item type to text and select the value inside the item*/ item.attr("type", "text").select(); /*to copy the text inside the item*/ document.execCommand("copy"); /*to change the item type to hidden*/ item.attr("type", "hidden"); /*to show success message (Optional)*/ apex.message.showPageSuccess('Copied to Clipboard!'); }


Click here for DEMO




HAPPY CODING!!! 

Thank you :)  

Comments

Post a Comment

Popular posts from this blog

Allow Only Number/Decimal values In a Number/Text Field Using JavaScript in Oracle APEX

Display and Edit CLOB Content in Oracle APEX