reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

`:default-checked` doesn't add value to the state #76

Closed smogg closed 8 years ago

smogg commented 8 years ago

When using :default-checked on radio buttons:

[:input {:field :radio :value :one :name :radio-test :default-checked true} "one"]
[:input {:field :radio :value :two :name :radio-test} "two"]

The first button is (visually) selected, but the state value is not set.

Similar issue to #74

yogthos commented 8 years ago

Is there value in having both :checked and :default-checked for setting the default value?

smogg commented 8 years ago

:checked does set the initial value in the state, but it makes radios unusable. Apparently, they are read only after using it, so you have to write your own on-change events to let users use them. :default-checked Makes radios (visually) selected and you can actually click to change the radio selection without adding any additional code, but the state is not updated initially.

yogthos commented 8 years ago

The idea is that the form elements represent the state in the atom though. I think the case where the element looks selected on the UI, but its value is not populated in the atom would be a bug.

yogthos commented 8 years ago

Unless I'm misunderstanding the intent of the change?

yogthos commented 8 years ago

Ah ok I tried it just now and see what you mean, with :checked the value in the ui can't be updated, while it does change in the atom. So, the idea would be to use :default-checked to set the initial state instead.

yogthos commented 8 years ago

Just pushed out the fix to Clojars with 0.5.13, let me know if that addresses the issue.

smogg commented 8 years ago

Yup, that works. Thanks!

smogg commented 8 years ago

I think this can be closed now?

yogthos commented 8 years ago

yeah think so :)