How I can add checkbox with simple_form without association with model? I want to create checkbox which will handle some javascript events, but don\'t know? Maybe I miss som
Add this to app/inputs/arbitrary_boolean_input.rb:
class ArbitraryBooleanInput < SimpleForm::Inputs::BooleanInput
def input(wrapper_options = nil)
tag_name = "#{@builder.object_name}[#{attribute_name}]"
template.check_box_tag(tag_name, options['value'] || 1, options['checked'], options)
end
end
then use it in your views like:
= simple_form_for(@some_object, remote: true, method: :put) do |f|
= f.simple_fields_for @some_object.some_nested_object do |nested_f|
= nested_f.input :some_param, as: :arbitrary_boolean
i.e. The above implementation supports nested fields correctly. Other solutions I've seen do not.
Note: This example is HAML.