Initial values for checkboxes and radio buttons
schpaa opened this issue · comments
As the title says, how would I go about supplying default values for radio-buttons and checkboxes?
I am giving you an example of both:
[fork/form {:initial-values {"checkbox" true
"gender" "female"}}
(fn [{:keys [db
values
handle-change
handle-blur]}]
[:div
;; radio buttons
[:input
{:type "radio"
:name "gender"
:value "male"
:checked (= "male" (values "gender"))
:on-change handle-change
:on-blur handle-blur}]
[:label {:for "male"} "Male"]
[:br]
[:input
{:type "radio"
:name "gender"
:value "female"
:checked (= "female" (values "gender"))
:on-change handle-change
:on-blur handle-blur}]
[:label {:for "female"} "Female"]
[:br][:br]
;; checkbox
[:span
[:input
{:name "checkbox"
:type "checkbox"
:checked (values "checkbox" false)
:on-change handle-change
:on-blur handle-blur}]
"Click me"]])]
Perfect, thank you!