I have JavaScript in one of my Classic Designer forms that will copy the value of one of the fields to the user's clipboard on page load:
/* Copies Field2 text to clipboard upon page load */ $(document).ready(function(){ var text = document.getElementById("Field2").textContent; navigator.clipboard.writeText(text).then(() => { console.log('Content copied to clipboard'); /* Resolved - text copied to clipboard successfully */ },() => { console.error('Failed to copy'); /* Rejected - text failed to copy to the clipboard */ }); });
This same code does not work in the Modern Designer. I've tried adjusting it for the Modern Designer as follows:
/* Copies Field2 text to clipboard upon page load */ $(document).ready(function(){ var text = LFForm.getFieldValues({fieldId: 2}); navigator.clipboard.writeText(text).then(() => { console.log('Content copied to clipboard'); /* Resolved - text copied to clipboard successfully */ },() => { console.error('Failed to copy'); /* Rejected - text failed to copy to the clipboard */ }); });
However, this does not work. Does the Modern Designer JavaScript support `navigator.clipboard.writeText()`? If not, is there any other supported way to do this?