Skip to content
Browse files

Merge pull request #972 from plataformatec/issue-971

collection input that uses automatic collection translation properly sets checked values
  • Loading branch information...
2 parents 624eb39 + 03396db commit 4052bc371b233e1e38924f9f4c83e0f897227b2d @nashby nashby committed Jan 4, 2014
Showing with 17 additions and 1 deletion.
  1. +2 −0 CHANGELOG.md
  2. +1 −1 lib/simple_form/inputs/collection_input.rb
  3. +14 −0 test/inputs/collection_check_boxes_input_test.rb
View
2 CHANGELOG.md
@@ -9,6 +9,8 @@
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
### bug fix
+ * Collection input that uses automatic collection translation properly sets checked values.
+ Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
## 3.0.1
View
2 lib/simple_form/inputs/collection_input.rb
@@ -90,7 +90,7 @@ def collection_includes_basic_objects?(collection_classes)
def translate_collection
if translated_collection = translate(:options)
@collection = collection.map do |key|
- [translated_collection[key] || key, key]
+ [translated_collection[key] || key, key.to_s]
end
true
end
View
14 test/inputs/collection_check_boxes_input_test.rb
@@ -53,6 +53,20 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
end
end
+ test 'input that uses automatic collection translation for check_boxes should properly set checked values' do
+ store_translations(:en, simple_form: { options: { defaults: {
+ gender: { male: 'Male', female: 'Female'}
+ } } } ) do
+ @user.gender = 'male'
+
+ with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
+ assert_select 'input[type=checkbox][value=male][checked=checked]'
+ assert_select 'input[type=checkbox][value=female]'
+ assert_select 'label.collection_check_boxes', 'Male'
+ assert_select 'label.collection_check_boxes', 'Female'
+ end
+ end
+
test 'input check boxes does not wrap the collection by default' do
with_input_for @user, :active, :check_boxes

0 comments on commit 4052bc3

Please sign in to comment.
Something went wrong with that request. Please try again.