Просмотр исходного кода

support boolean fields.

note that the values are wrapped in `js/Boolean` objects as apparently
`(satisfies? ICloneable false)` is false.
Lucas Stadler лет назад: 12
Родитель
Сommit
954120e535
1 измененных файлов с 19 добавлено и 2 удалено
  1. 19 2
      clj/clarity/cljs/clarity.cljs

+ 19 - 2
clj/clarity/cljs/clarity.cljs

@ -6,14 +6,18 @@
6 6
7 7
(enable-console-print!)
8 8
9
(extend-type string
9
(extend-type js/Boolean
10 10
  ICloneable
11
  (-clone [s] (js/String. s)))
11
  (-clone [b] b))
12 12
13 13
(extend-type number
14 14
  ICloneable
15 15
  (-clone [n] (js/Number. n)))
16 16
17
(extend-type string
18
  ICloneable
19
  (-clone [s] (js/String. s)))
20
17 21
; data for one node: type and optionally data
18 22
;  if data is present, fill the node with the data
19 23
;  on input, check if input conforms to data, if it
@ -36,6 +40,12 @@
36 40
      (map? type) (get-type (:type type))
37 41
      :else type)))
38 42
43
(defmethod empty-value 'Boolean [{:keys [default]}]
44
  (js/Boolean.
45
    (if-not (nil? default)
46
      default
47
      false)))
48
39 49
(defmethod empty-value 'Number [{:keys [default]}]
40 50
  (or default 0))
41 51
@ -65,6 +75,12 @@
65 75
      (map? type) (:type type)
66 76
      :else type)))
67 77
78
(defmethod make-typed-input 'Boolean [bool owner]
79
  (om/component
80
    (dom/input #js {:type "checkbox"
81
                    :checked (.valueOf bool)
82
                    :onChange #(om/update! bool (fn [_ n] n) (js/Boolean. (.. % -target -checked)))})))
83
68 84
(defmethod make-typed-input 'Number [number owner]
69 85
  (om/component
70 86
    (dom/input #js {:type "number"
@ -128,6 +144,7 @@
128 144
                                  (Value :de)
129 145
                                  (Value :fr)
130 146
                                  (Value :jp))
147
                     :fun Boolean
131 148
                     :gender Keyword})]
132 149
    (atom
133 150
     {:type type