Last active
March 31, 2021 00:43
-
-
Save oakmac/1acaaa380820a599278e0a77f362761e to your computer and use it in GitHub Desktop.
dom helpers functions
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
;; this code licensed as CC0 1.0 Universal (SPDX: CC0-1.0) | |
(ns ^{:doc "DOM helpers" | |
:author "Chris Oakman"} | |
com.oakmac.some-project.util.dom | |
(:require | |
[goog.dom :as gdom] | |
[goog.dom.forms :as gforms])) | |
;; TODO: this could be variadic with some options | |
(defn form->values | |
"Returns the values from a DOM Form Element as a ClojureScript Map" | |
[el] | |
(let [el (gdom/getElement el) | |
form-data-map (gforms/getFormDataMap el) | |
form-data-obj (.toObject ^goog.structs.Map form-data-map) | |
form-data (js->clj form-data-obj)] | |
(reduce | |
(fn [acc [k itm]] | |
(assoc acc (keyword k) (first itm))) | |
{} | |
form-data))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment