Skip to content

Instantly share code, notes, and snippets.

@breck7
Created September 13, 2017 17:48
Show Gist options
  • Save breck7/8f2095f2fd9ed56b870fe645b030cb6c to your computer and use it in GitHub Desktop.
Save breck7/8f2095f2fd9ed56b870fe645b030cb6c to your computer and use it in GitHub Desktop.
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