瀏覽代碼

support keyword fields.

breaks when `read-keyword` returns nil, e.g. when the keyword field is
empty. is this a special case? or should i set the value in the map, not
in the entry?
Lucas Stadler 12 年之前
父節點
當前提交
f77002c3eb
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. 11 0
      clj/clarity/cljs/clarity.cljs

+ 11 - 0
clj/clarity/cljs/clarity.cljs

@ -30,6 +30,16 @@
30 30
      (keyword name)
31 31
      nil)))
32 32
33
(defn typed-keyword [kw owner]
34
  (om/component
35
    (dom/input #js {:type "text"
36
                    :className "field"
37
                    :value (om/value kw)
38
                    :pattern "^:(\\w+|\\w+(\\.\\w+)*\\/\\w+)$"
39
                    :onChange (fn [ev]
40
                                (when (valid? (.-target ev))
41
                                  (om/update! kw (fn [o n] n) (read-keyword (.. ev -target -value)))))})))
42
33 43
(defn typed-string [string owner]
34 44
  (om/component
35 45
    (dom/input #js {:type "text"
@ -45,6 +55,7 @@
45 55
    (render [_]
46 56
      (dom/div nil
47 57
        (dom/span nil "{")
58
        (om/build typed-keyword (:kw data))
48 59
        (om/build typed-string (:str data))
49 60
        (dom/span nil "}")))))
50 61