mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
collection input that uses automatic collection translation properly sets checked values
closes #971
This commit is contained in:
parent
6ce9a15a5a
commit
03396dbb07
3 changed files with 17 additions and 1 deletions
|
@ -9,6 +9,8 @@
|
||||||
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
|
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
|
||||||
|
|
||||||
### bug fix
|
### 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)
|
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
|
|
|
@ -90,7 +90,7 @@ module SimpleForm
|
||||||
def translate_collection
|
def translate_collection
|
||||||
if translated_collection = translate(:options)
|
if translated_collection = translate(:options)
|
||||||
@collection = collection.map do |key|
|
@collection = collection.map do |key|
|
||||||
[translated_collection[key] || key, key]
|
[translated_collection[key] || key, key.to_s]
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,6 +53,20 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
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
|
test 'input check boxes does not wrap the collection by default' do
|
||||||
with_input_for @user, :active, :check_boxes
|
with_input_for @user, :active, :check_boxes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue