|
5 | 5 | [sablono.core :refer-macros [html]]
|
6 | 6 | [om-widgets.utils :as utils]
|
7 | 7 | [cljs.reader :as reader]
|
8 |
| - [om-widgets.utils :as u])) |
| 8 | + [om-widgets.utils :as u] |
| 9 | + [pallet.thread-expr :as th])) |
9 | 10 |
|
10 | 11 |
|
11 | 12 | (defn- option
|
12 | 13 | [[k v] owner]
|
13 | 14 | (reify
|
14 | 15 | om/IRenderState
|
15 | 16 | (render-state [_ {:keys [selected]}]
|
16 |
| - (let [opts (->> {:value (pr-str {:value k})} |
17 |
| - (merge (when (= k selected) {:selected 1})))] |
| 17 | + (let [value (if (map? k) |
| 18 | + (into (sorted-map) k) |
| 19 | + k) |
| 20 | + opts (->> {:value (pr-str {:value value})} |
| 21 | + (merge (when (= value selected) {:selected 1})))] |
18 | 22 | (html
|
19 | 23 | (if (map? v)
|
20 |
| - (u/make-childs [:optgroup {:label k}] (om/build-all option v)) |
| 24 | + (u/make-childs [:optgroup {:label value}] (om/build-all option v)) |
21 | 25 | (dom/option (clj->js opts) v)))))))
|
22 | 26 |
|
23 | 27 | (defn- combo
|
|
45 | 49 | "om-widgets-combobox-readonly")])
|
46 | 50 | :disabled (or (:disabled state) (if (:read-only state) true false))
|
47 | 51 | :onBlur (:onBlur state)
|
48 |
| - ;:value (pr-str {:value value}) |
| 52 | + :value (cond |
| 53 | + (nil? value) (pr-str {:value nil}) |
| 54 | + (map? value) (pr-str {:value (into (sorted-map) value)}) |
| 55 | + :else (pr-str {:value value})) |
49 | 56 | :id (:id state)}
|
50 | 57 | (merge (when (:tabIndex state)) {:tabIndex (:tabIndex state)})
|
51 |
| - (merge (when (:read-only state) {:readOnly true})) |
52 |
| - (merge (when (nil? value) {:value (pr-str {:value nil})})))] |
| 58 | + (merge (when (:read-only state) {:readOnly true})))] |
53 | 59 | (apply dom/select (clj->js opts)
|
54 | 60 | ;; create an empty value to override <select> default behaviour of always selecting the first item
|
55 | 61 | ;; this plays well with required values or form validation
|
|
0 commit comments