Skip to content

Commit c424477

Browse files
Added copy to clipboard functionality
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent a6a8422 commit c424477

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

js/formDataToJson.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,30 @@ async function populateCodeJson(data) {
7373
return codeJson;
7474
}
7575

76+
async function copyToClipboard(event){
77+
event.preventDefault();
78+
var textArea = document.getElementById("json-result");
79+
textArea.select();
80+
document.execCommand("copy")
81+
}
82+
7683
// Creates code.json and triggers file download
7784
async function downloadFile(data) {
7885
delete data.submit;
7986
const codeJson = await populateCodeJson(data);
8087

8188
const jsonString = JSON.stringify(codeJson, null, 2);
82-
const blob = new Blob([jsonString], { type: "application/json" });
89+
// const blob = new Blob([jsonString], { type: "application/json" });
90+
document.getElementById("json-result").value = jsonString;
8391

84-
// Create anchor element and create download link
85-
const link = document.createElement("a");
86-
link.href = URL.createObjectURL(blob);
87-
link.download = "code.json";
92+
// // Create anchor element and create download link
93+
// const link = document.createElement("a");
94+
// link.href = URL.createObjectURL(blob);
95+
// link.download = "code.json";
8896

89-
// Trigger the download
90-
link.click();
97+
// // Trigger the download
98+
// link.click();
9199
}
92100

93101
window.downloadFile = downloadFile;
102+
window.copyToClipboard = copyToClipboard;

js/generateFormComponents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ async function createFormComponents() {
299299
// Add submit button to form
300300
components.push({
301301
type: "button",
302-
label: "Submit",
302+
label: "Create code.json metadata",
303303
key: "submit",
304304
disableOnInvalid: false,
305305
input: true,
@@ -311,4 +311,4 @@ async function createFormComponents() {
311311
return components;
312312
}
313313

314-
window.createFormComponents = createFormComponents;
314+
window.createFormComponents = createFormComponents;

0 commit comments

Comments
 (0)