Skip to content

Instantly share code, notes, and snippets.

@ostronom
Created March 19, 2015 17:09
Show Gist options
  • Save ostronom/c2f99c9de7f0196043df to your computer and use it in GitHub Desktop.
Save ostronom/c2f99c9de7f0196043df to your computer and use it in GitHub Desktop.
(defn canonical-input-value [input]
(case (.toLowerCase (.getAttribute input "type"))
"checkbox" (.-checked input)
"textarea" (.-innerHTML input)
(.-value input)))
(defn input-pair [input]
[(.getAttribute input "name") (canonical-input-value input)])
(defn is-file? [input]
(= (.getAttribute input "type") "file"))
(defn fetch-form-values [form]
(into {} (comp (remove is-file?) (map input-pair)) (.querySelectorAll form "input[name]")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment