Skip to content

Commit f592754

Browse files
mtnygardweavejester
authored andcommitted
Added a radio button form helper
1 parent dd36e21 commit f592754

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/compojure/html/form_helpers.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@
6666
:value value
6767
:checked checked?}]))
6868

69+
(defn radio-button
70+
"Creates a radio button."
71+
([name]
72+
(radio-button name (*params* name)))
73+
([name checked?]
74+
(radio-button name checked? "true"))
75+
([name checked? value]
76+
[:input {:type "radio"
77+
:name (str* name)
78+
:id (str* name)
79+
:value value
80+
:checked checked?}]))
81+
6982
(defn select-options
7083
"Turn a collection into a set of option tags."
7184
([options]

test/compojure/html/form_helpers.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@
3131
:value "true"
3232
:checked nil}])))
3333

34+
(deftest test-radio-button
35+
(is (= (radio-button :foo)
36+
[:input {:type "radio"
37+
:id "foo"
38+
:name "foo"
39+
:value "true"
40+
:checked nil}])))
41+
42+
(deftest test-radio-button-selected
43+
(is (= (radio-button :foo true "abcdef")
44+
[:input {:type "radio"
45+
:id "foo"
46+
:name "foo"
47+
:value "abcdef"
48+
:checked true}])))
49+
3450
(deftest select-options-with-values
3551
(is (= (select-options [["a" "1"] ["b" "2"] ["c" "3"]])
3652
'([:option {:value "1"} "a"]

0 commit comments

Comments
 (0)