Browse files

Added display value multimethod

  • Loading branch information...
1 parent bc6b8ca commit 309447137bbb00339dfbb6be8abe8c406e2a3159 @mylesmegyesi mylesmegyesi committed Dec 11, 2013
6 spec/cljs/com/eighthlight/filament/inplace_field_spec.cljs
@@ -47,12 +47,18 @@
(should= "foobar" (inplace/inplace-value (inplace/input-node result)))))
(defmethod inplace/inplace-value "whacky" [input] "WHACKY VALUE!")
+ (defmethod inplace/display-value "whacky" [input model field-key] [model field-key])
(defmethod inplace/set-inplace-value "whacky" [input] "???")
(it "gets the value from custom inputs"
(let [result (dom/single-node (h/html (inplace/inplace-field "abc123" [:div#custom {:type "whacky"}])))]
(should= "WHACKY VALUE!" (inplace/inplace-value (inplace/input-node result)))))
+ (it "gets the value from custom inputs"
+ (let [result (dom/single-node (h/html (inplace/inplace-field "abc123" [:div#custom {:type "whacky"}])))]
+ (should= [{:my :model} :the-field-key]
+ (inplace/display-value (inplace/input-node result) {:my :model} :the-field-key))))
(it "records activation"
13 src/cljs/com/eighthlight/filament/inplace_field.cljs
@@ -25,6 +25,10 @@
(defn input-node [e] (nth (dom/children (input-container e)) 1))
(defn errors-node [e] (nth (dom/children (input-container e)) 0))
+(defmulti display-value #(dom/attr % "type"))
+(defmethod display-value :default [input model field-key]
+ (str (get model field-key)))
(defmulti inplace-value #(dom/attr % "type"))
(defmethod inplace-value :default [node] (dom/value node))
@@ -46,13 +50,6 @@
(defmethod register-escape-callback :default [node callback]
(event/listen! node :keyup (fn [e] (when (util/ESC? e) (callback)))))
-(defn display-value [model field-key]
- (when-let [value (get model field-key)]
- (if (map? value)
- (:display-value value)
- (str value))))
(defn- display-errors [field errors]
(let [html (apply str (map #(str "<p>" % "</p>") errors))
errors-n (errors-node field)]
@@ -72,7 +69,7 @@
field-key (dom/get-data e :field-key)]
(fx/hide! (input-container e))
(fx/remove-spinner (input-container e))
- (dom/set-text! (value-node e) (display-value model field-key))
+ (dom/set-text! (value-node e) (display-value e model field-key))
(fx/show! (value-container e))
(hide-errors e)
(dom/set-data! e :mode :view)))

0 comments on commit 3094471

Please sign in to comment.