2010-07-06 09:24:12 +00:00
|
|
|
module SimpleForm
|
|
|
|
module Inputs
|
|
|
|
class BooleanInput < Base
|
|
|
|
def input
|
|
|
|
@builder.check_box(attribute_name, input_html_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def label_input
|
2012-01-26 13:30:08 +00:00
|
|
|
if options[:label] == false
|
|
|
|
input
|
|
|
|
elsif nested_style?
|
|
|
|
@builder.label(attribute_name) { input }
|
|
|
|
else
|
|
|
|
input + label
|
|
|
|
end
|
2010-07-06 09:24:12 +00:00
|
|
|
end
|
|
|
|
|
2011-09-03 09:13:29 +00:00
|
|
|
private
|
2010-07-06 09:24:12 +00:00
|
|
|
|
2012-01-26 13:30:08 +00:00
|
|
|
def nested_style?
|
2012-01-26 17:44:13 +00:00
|
|
|
options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
|
2012-01-26 13:30:08 +00:00
|
|
|
end
|
|
|
|
|
2010-07-06 09:24:12 +00:00
|
|
|
# Booleans are not required by default because in most of the cases
|
|
|
|
# it makes no sense marking them as required. The only exception is
|
|
|
|
# Terms of Use usually presented at most sites sign up screen.
|
2011-12-04 12:00:39 +00:00
|
|
|
def required_by_default?
|
2010-07-06 09:24:12 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-01-26 13:30:08 +00:00
|
|
|
end
|