diff --git a/css/styles.css b/css/styles.css index 4a1055a..143e902 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,3 +1,7 @@ body { margin: 20px; +} + +textarea { + margin-bottom: 10px; } \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..a0e1976 Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html index 5702d28..ed04630 100644 --- a/index.html +++ b/index.html @@ -40,7 +40,7 @@ }).then(function (form) { form.on("submit", function (submission) { console.log("form submission here:", submission); - downloadFile(submission.data); + createCodeJson(submission.data); }); }); }) @@ -52,5 +52,11 @@
+
+ + + + +
diff --git a/js/formDataToJson.js b/js/formDataToJson.js index d657683..f517caf 100644 --- a/js/formDataToJson.js +++ b/js/formDataToJson.js @@ -73,12 +73,31 @@ async function populateCodeJson(data) { return codeJson; } -// Creates code.json and triggers file download -async function downloadFile(data) { +// Creates code.json object +async function createCodeJson(data) { delete data.submit; const codeJson = await populateCodeJson(data); const jsonString = JSON.stringify(codeJson, null, 2); + document.getElementById("json-result").value = jsonString; +} + +// Copies code.json to clipboard +async function copyToClipboard(event){ + event.preventDefault(); + + var textArea = document.getElementById("json-result"); + textArea.select(); + document.execCommand("copy") +} + +// Triggers local file download +async function downloadFile(event) { + event.preventDefault(); + + const codeJson = document.getElementById("json-result").value + const jsonObject = JSON.parse(codeJson); + const jsonString = JSON.stringify(jsonObject, null, 2); const blob = new Blob([jsonString], { type: "application/json" }); // Create anchor element and create download link @@ -90,4 +109,6 @@ async function downloadFile(data) { link.click(); } +window.createCodeJson = createCodeJson; +window.copyToClipboard = copyToClipboard; window.downloadFile = downloadFile; diff --git a/js/generateFormComponents.js b/js/generateFormComponents.js index d9e3086..e386038 100644 --- a/js/generateFormComponents.js +++ b/js/generateFormComponents.js @@ -299,7 +299,7 @@ async function createFormComponents() { // Add submit button to form components.push({ type: "button", - label: "Submit", + label: "Generate code.json metadata", key: "submit", disableOnInvalid: false, input: true, @@ -311,4 +311,4 @@ async function createFormComponents() { return components; } -window.createFormComponents = createFormComponents; +window.createFormComponents = createFormComponents; \ No newline at end of file