Skip to content

Commit 630746f

Browse files
committed
fix combo value selection when a map is passed as key
1 parent 105c377 commit 630746f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

‎project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.clojars.intception/om-widgets "0.3.35"
1+
(defproject org.clojars.intception/om-widgets "0.3.36"
22
:description "Widgets for OM/React"
33
:url "https://github.com/orgs/intception/"
44
:license {:name "Eclipse Public License"

‎src/om_widgets/combobox.cljs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
[sablono.core :refer-macros [html]]
66
[om-widgets.utils :as utils]
77
[cljs.reader :as reader]
8-
[om-widgets.utils :as u]))
8+
[om-widgets.utils :as u]
9+
[pallet.thread-expr :as th]))
910

1011

1112
(defn- option
1213
[[k v] owner]
1314
(reify
1415
om/IRenderState
1516
(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})))]
1822
(html
1923
(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))
2125
(dom/option (clj->js opts) v)))))))
2226

2327
(defn- combo
@@ -45,11 +49,13 @@
4549
"om-widgets-combobox-readonly")])
4650
:disabled (or (:disabled state) (if (:read-only state) true false))
4751
: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}))
4956
:id (:id state)}
5057
(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})))]
5359
(apply dom/select (clj->js opts)
5460
;; create an empty value to override <select> default behaviour of always selecting the first item
5561
;; this plays well with required values or form validation

0 commit comments

Comments
 (0)