Model Setup |
(defrecord UserModel [name email twitter]) (def my-user (atom (UserModel. "Creighton Kirkendall" "ckirkendall@gmail.com" "@crkirkendall"))) |
Validators |
(defn user-validator [new-val] (let [check-map {:name (not (nil? (re-matches #"\S+.*" (:name new-val)))) :email (not (nil? (re-matches #".+@.+\..+" (:email new-val)))) :twitter (not (nil? (re-matches #"@\S+" (:twitter new-val))))}] (if (not-every? true? (vals check-map)) (throw (FormError. check-map)) new-val))) (set-validator! my-user user-validator) |
Watchers |
(add-watch my-user :user-view (fn [key ref old-val new-val] (user-view new-val))) |
Views |
(defn user-view [user-val] (em/at (by-id "user-div") [".name"] (em/content (:name user-val)) [".email"] (em/content (:email user-val)) [".twitter"] (em/content (:twitter user-val)))) |