Permalink
Browse files

Add form-values helper to dom

  • Loading branch information...
1 parent 9502bc3 commit b62b61801d396b7a9192b459a6e1e1c8c702861f @zk committed Oct 20, 2013
Showing with 19 additions and 2 deletions.
  1. +19 −2 src/cljs/nsfw/dom.cljs
@@ -112,7 +112,8 @@
(defn val
([el]
- (forms/getValue (unwrap el)))
+ (let [res (forms/getValue (unwrap el))]
+ (when-not (empty? res) res)))
([el new-value]
(doseq [el (ensure-coll el)]
(forms/setValue el new-value))
@@ -682,4 +683,20 @@
name
safe-upper-case)
(pr-str data)
- (clj->js headers))))
+ (clj->js headers))))
+
+(defn form-values [$el]
+ (let [$els (->> ["input" "select" "textarea"]
+ (map #(query $el %))
+ (reduce concat))]
+ (->> $els
+ (map (fn [$el]
+ [(attr $el :name)
+ (val $el)]))
+ (clojure.core/remove #(nil? (first %)))
+ (map #(vector (keyword (first %))
+ (second %)))
+ (into {}))))
+
+(defn parent [el]
+ (dom/getParentElement el))

0 comments on commit b62b618

Please sign in to comment.