Fork me on GitHub
#reagent
<
2021-02-25
>
Audrius12:02:19

Hello, how to make sense of [:input {:type "checkbox" :on-change #(js/console.log %)}] :on-change argument? I just want to find out if it is selected or not...

vanelsas12:02:45

Checkbox has a field called :checked that you can use to check/uncheck the checkbox. You could try something like this (haven't verified if it works).

✔️ 1
kozmicluis17:02:49

same way you'd make sense of it in javascript, using ".target.checked"

kozmicluis17:02:39

[:input {:type "checkbox" :on-change #(-> % .-target .-checked js/console.log)}]

kozmicluis17:02:45

or you could bind the property to state, as vanelsas said.

kozmicluis17:02:30

as he suggests, since the checkbox's initial state is "non checked", you can safely assume most of the time that the first on-change event means the checkbox changed to "checked", and so forth.