diff --git a/src/hiccup/form.clj b/src/hiccup/form.clj index 7c60fae..c072252 100644 --- a/src/hiccup/form.clj +++ b/src/hiccup/form.clj @@ -74,6 +74,12 @@ :value value :checked checked?}])) +(defn- selected? [x selected] + (boolean (cond + (sequential? selected) ((set selected) x) + (ifn? selected) (selected x) + :else (= x selected)))) + (defelem select-options "Creates a seq of option tags from a collection." ([coll] (select-options coll nil)) @@ -83,8 +89,8 @@ (let [[text val] x] (if (sequential? val) [:optgroup {:label text} (select-options val selected)] - [:option {:value val :selected (= val selected)} text])) - [:option {:selected (= x selected)} x])))) + [:option {:value val :selected (selected? val selected)} text])) + [:option {:selected (selected? x selected)} x])))) (defelem drop-down "Creates a drop-down box using the `