diff --git a/js/formDataToJson.js b/js/formDataToJson.js index c6e6439..11ecb1d 100644 --- a/js/formDataToJson.js +++ b/js/formDataToJson.js @@ -86,10 +86,23 @@ async function createCodeJson(data) { document.getElementById("json-result").value = jsonString; } +function checkIfResponseGenerated() { + const textArea = document.getElementById("json-result"); + if(!textArea.value || textArea.value.trim() === '') { + alert("Please generate your response first by clicking 'Generate your response!' button."); + return false; + } + return true; +} + // Copies json to clipboard async function copyToClipboard(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + var textArea = document.getElementById("json-result"); textArea.select(); document.execCommand("copy") @@ -243,6 +256,10 @@ async function createPR(projectURL, token) { async function createProjectPR(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + const textArea = document.getElementById("json-result"); const JSONObj = JSON.parse(textArea.value) @@ -285,6 +302,10 @@ async function createProjectPR(event) { async function downloadFile(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + const codeJson = document.getElementById("json-result").value const jsonObject = JSON.parse(codeJson); const jsonString = JSON.stringify(jsonObject, null, 2); @@ -326,6 +347,10 @@ function generateIssueBody(JSONObj) { async function createGitHubIssueForm(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + const textArea = document.getElementById("json-result"); const JSONObj = JSON.parse(textArea.value); @@ -377,6 +402,10 @@ function createGitHubNewIssueURL(title, body) { async function createAutoGitHubIssue(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + const textArea = document.getElementById("json-result"); const JSONObj = JSON.parse(textArea.value); @@ -446,6 +475,10 @@ async function createIssueOnGitHub(token, title, body) { async function emailFile(event) { event.preventDefault(); + if (!checkIfResponseGenerated()) { + return; + } + const codeJson = document.getElementById("json-result").value const jsonObject = JSON.parse(codeJson);