reform: On form error, simple_form association helpers are not filled
I use the following initializer to make association work (as proposed here: https://github.com/apotonick/reform/issues/122):
# /config/initializers/reform.rb
Reform::Form::ModelReflections.module_eval do
# TODO: This is a hack for making simple_form association inputs work with reform.
# This should be removed once the problem is fixed in the gems.
def self.included(base)
def base.reflect_on_association(*args)
model_name.to_s.constantize.reflect_on_association(*args)
end
super
end
end
# Form.rb
class Form < Reform::Form
include ModelReflections
end
And this code for my association:
# ClientForm.rb
class ClientForm < Form
model :client
properties :name, :language_ids
end
# _form.html.erb
<%= f.association :languages, as: :check_boxes, collection: Language.all, disabled: [default_language.id] %>
But on error, the content just disappear. If there’s no error, it saves normally and everything is fine!
I use Rails 4.2.3, Simple Form 3.1.0 and Reform 2.0.1. Does someone have an idea what is happening?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 17 (13 by maintainers)
Quick fix: add
checked: @form.language_ids
to form input. Also, doesn’t work with virtual attribute too. You must setchecked
manually. Can you add that to your test app @coatezy ?