Get rid of the enabled/disabled in favor of has_*? syntax.
This commit is contained in:
parent
fcd049adc6
commit
6bf59dd508
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ module SimpleForm
|
|||
def input
|
||||
template.capture(&@block)
|
||||
end
|
||||
|
||||
def has_placeholder?
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -24,6 +24,10 @@ module SimpleForm
|
|||
options
|
||||
end
|
||||
|
||||
def has_placeholder?
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collection
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class NumericInput < Base
|
||||
enable :placeholder
|
||||
|
||||
def input
|
||||
add_size!
|
||||
if SimpleForm.html5
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class PasswordInput < Base
|
||||
enable :placeholder
|
||||
|
||||
def input
|
||||
add_size!
|
||||
add_maxlength!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue