diff --git a/lib/simple_form/components/disabled.rb b/lib/simple_form/components/disabled.rb index 9f57a8a2..35ca288e 100644 --- a/lib/simple_form/components/disabled.rb +++ b/lib/simple_form/components/disabled.rb @@ -12,14 +12,6 @@ module SimpleForm def has_disabled? options[:disabled] == true end - - private - - alias :enabled_disabled :disabled - - def disabled_disabled - nil - end end end end \ No newline at end of file diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index fc9a3bd0..c6d26a1e 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -11,12 +11,6 @@ module SimpleForm protected - alias :enabled_error :error - - def disabled_error - nil - end - def error_text if options[:error_prefix] options[:error_prefix] + " " + errors.send(error_method) diff --git a/lib/simple_form/components/hints.rb b/lib/simple_form/components/hints.rb index a97f2255..5529e4ae 100644 --- a/lib/simple_form/components/hints.rb +++ b/lib/simple_form/components/hints.rb @@ -2,15 +2,13 @@ module SimpleForm module Components module Hints def hint - (options.delete(:hint) || translate(:hints)).presence + (options.delete(:hint) || translate(:hints)).presence if has_hint? end private - alias :enabled_hint :hint - - def disabled_hint - nil + def has_hint? + true end end end diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index 63ba0884..d71da8c1 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -22,6 +22,7 @@ module SimpleForm end def label + return "" unless has_label? if input_type_should_generate_for_attribute? @builder.label(label_target, label_text, label_html_options) else @@ -45,10 +46,8 @@ module SimpleForm protected - alias :enabled_label :label - - def disabled_label - "" + def has_label? + true end def raw_label_text #:nodoc: diff --git a/lib/simple_form/components/placeholders.rb b/lib/simple_form/components/placeholders.rb index 131791ad..87bb0a08 100644 --- a/lib/simple_form/components/placeholders.rb +++ b/lib/simple_form/components/placeholders.rb @@ -2,21 +2,15 @@ module SimpleForm module Components module Placeholders def placeholder - nil # This component is disabled by default. - end - - def has_placeholder? - options[:placeholder] != false && placeholder_text.present? - end - - private - - def enabled_placeholder input_html_options[:placeholder] ||= placeholder_text if has_placeholder? nil end - alias :disabled_placeholder :placeholder + def has_placeholder? + placeholder_text.present? + end + + private def placeholder_text @placeholder_text ||= options[:placeholder] || translate(:placeholders) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 24d5c70a..8b298d4f 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -15,15 +15,6 @@ module SimpleForm include SimpleForm::Components::LabelInput include SimpleForm::Components::Placeholders - # Enables certain components support to the given input. - def self.enable(*args) - args.each { |m| alias_method m, :"enabled_#{m}" } - end - - def self.disable(*args) - args.each { |m| alias_method m, :"disabled_#{m}" } - end - attr_reader :attribute_name, :column, :input_type, :reflection, :options, :input_html_options, :input_html_classes diff --git a/lib/simple_form/inputs/block_input.rb b/lib/simple_form/inputs/block_input.rb index 36278789..58ff6003 100644 --- a/lib/simple_form/inputs/block_input.rb +++ b/lib/simple_form/inputs/block_input.rb @@ -9,6 +9,10 @@ module SimpleForm def input template.capture(&@block) end + + def has_placeholder? + false + end end end end \ No newline at end of file diff --git a/lib/simple_form/inputs/boolean_input.rb b/lib/simple_form/inputs/boolean_input.rb index 9255bfd5..d45dd3d7 100644 --- a/lib/simple_form/inputs/boolean_input.rb +++ b/lib/simple_form/inputs/boolean_input.rb @@ -9,6 +9,10 @@ module SimpleForm input + (options[:label] == false ? "" : label) end + def has_placeholder? + false + end + private # Booleans are not required by default because in most of the cases diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index d1ec9ec6..88e51d54 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -24,6 +24,10 @@ module SimpleForm options end + def has_placeholder? + false + end + private def collection diff --git a/lib/simple_form/inputs/date_time_input.rb b/lib/simple_form/inputs/date_time_input.rb index 2a323d9b..f4f5e0f1 100644 --- a/lib/simple_form/inputs/date_time_input.rb +++ b/lib/simple_form/inputs/date_time_input.rb @@ -5,12 +5,16 @@ module SimpleForm @builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options) end - private + def has_placeholder? + false + end def has_required? false end + private + def label_target case input_type when :date, :datetime diff --git a/lib/simple_form/inputs/file_input.rb b/lib/simple_form/inputs/file_input.rb index a0ee2908..e57683e2 100644 --- a/lib/simple_form/inputs/file_input.rb +++ b/lib/simple_form/inputs/file_input.rb @@ -4,6 +4,10 @@ module SimpleForm def input @builder.file_field(attribute_name, input_html_options) end + + def has_placeholder? + false + end end end end diff --git a/lib/simple_form/inputs/hidden_input.rb b/lib/simple_form/inputs/hidden_input.rb index a76d4505..312e755a 100644 --- a/lib/simple_form/inputs/hidden_input.rb +++ b/lib/simple_form/inputs/hidden_input.rb @@ -1,12 +1,15 @@ module SimpleForm module Inputs class HiddenInput < Base - disable :label, :error, :hint - def input @builder.hidden_field(attribute_name, input_html_options) end + def has_label?() false end + def has_errors?() false end + def has_hint?() false end + def has_placeholder?() false end + private def attribute_required? diff --git a/lib/simple_form/inputs/numeric_input.rb b/lib/simple_form/inputs/numeric_input.rb index 320793c9..0be6d18f 100644 --- a/lib/simple_form/inputs/numeric_input.rb +++ b/lib/simple_form/inputs/numeric_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class NumericInput < Base - enable :placeholder - def input add_size! if SimpleForm.html5 diff --git a/lib/simple_form/inputs/password_input.rb b/lib/simple_form/inputs/password_input.rb index 986a9784..e3f62b5b 100644 --- a/lib/simple_form/inputs/password_input.rb +++ b/lib/simple_form/inputs/password_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class PasswordInput < Base - enable :placeholder - def input add_size! add_maxlength! diff --git a/lib/simple_form/inputs/priority_input.rb b/lib/simple_form/inputs/priority_input.rb index ff50e723..571d2af3 100644 --- a/lib/simple_form/inputs/priority_input.rb +++ b/lib/simple_form/inputs/priority_input.rb @@ -10,12 +10,12 @@ module SimpleForm options[:priority] || SimpleForm.send(:"#{input_type}_priority") end - protected - def has_required? false end + protected + def skip_include_blank? super || input_priority.present? end diff --git a/lib/simple_form/inputs/range_input.rb b/lib/simple_form/inputs/range_input.rb index 8304f6ed..6acf1cf3 100644 --- a/lib/simple_form/inputs/range_input.rb +++ b/lib/simple_form/inputs/range_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class RangeInput < NumericInput - disable :placeholder - def input if SimpleForm.html5 input_html_options[:type] ||= "range" @@ -11,6 +9,10 @@ module SimpleForm super end + + def has_placeholder? + false + end end end end diff --git a/lib/simple_form/inputs/string_input.rb b/lib/simple_form/inputs/string_input.rb index 1f9433c1..2b66d73a 100644 --- a/lib/simple_form/inputs/string_input.rb +++ b/lib/simple_form/inputs/string_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class StringInput < Base - enable :placeholder - def input input_html_options[:type] ||= input_type if SimpleForm.html5 && !string? add_maxlength! diff --git a/lib/simple_form/inputs/text_input.rb b/lib/simple_form/inputs/text_input.rb index 3e5cd517..a33ae871 100644 --- a/lib/simple_form/inputs/text_input.rb +++ b/lib/simple_form/inputs/text_input.rb @@ -1,8 +1,6 @@ module SimpleForm module Inputs class TextInput < Base - enable :placeholder - def input add_maxlength! @builder.text_area(attribute_name, input_html_options)