This topic is locked
[SOLVED]

copy to clipboard

1/13/2024 7:12:13 PM
PHPRunner General questions
A
aeaton2017 author

I have added a custom button to an edit page. my goal was to copyp field to the clipboard but its not doing anything. Thought

$("#value_copyp_1").select();

document.execCommand("copy");

$("#value_copyp_1").blur();

A
aeaton2017 author 1/14/2024

That field was readonly, so that was the reason it did not copy.. So I had to modify the js to alter the phone number to meet the custmer request.

var text = $("#value_phone_1").val();

// Remove the first two characters
var result = text.substring(2);

// Set the modified text back to the element (optional, depends on your use case)
$("#value_phone_1").val(result);

// Select the text in the element
$("#value_phone_1").select();

document.execCommand("copy");

$("text.substring(2);").blur();

fhumanes 1/14/2024

Hello,

The copy to the clipboard I have implemented in this example:
https://fhumanes.com/blog/gestor-de-proyectos/sistema-de-archivo-de-documentos-electronicos-edas/

The final code that makes the copy (associated with a button) is:

var path = result["path"];
navigator.clipboard.writeText(path)
.then(() => { ajax.setMessage("PATH: **"+path+ "** copied to the clipboard"); })
.catch((error) => { alert(`Copy failed! ${error}`); });

Greetings,
fernando