Created
September 13, 2017 17:48
-
-
Save breck7/8f2095f2fd9ed56b870fe645b030cb6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exportApplicationToTreeNotation() { | |
const selector = "input,textarea,select" | |
const nodes = $("#application_form") | |
.find(selector) | |
.get() | |
const lines = [] | |
nodes | |
.map(el => $(el)) | |
.filter(jq => { | |
const type = jq.attr("type") | |
if (["hidden", "submit"].includes(type)) return false | |
if (jq.attr("name").includes("recaptcha")) return false | |
if (type === "checkbox" && !jq.is(":checked")) return false | |
return true | |
}) | |
.map(jq => { | |
return { | |
name: jq.attr("name"), | |
value: jq.val() | |
} | |
}) | |
.forEach(pair => { | |
if (pair.value.includes("\n")) { | |
lines.push(`${pair.name}`) | |
lines.push(` ${pair.value.replace(/\n/g, "\n ")}`) | |
} else lines.push(`${pair.name} ${pair.value}`) | |
}) | |
return lines.join("\n") | |
} | |
console.log(exportApplicationToTreeNotation()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment