Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Provide enable/disable API.

  • Loading branch information...
commit f50e5bdaeac1c1427ebfd824bb163e33c9564019 1 parent ff64664
@josevalim josevalim authored
View
10 lib/simple_form/components/errors.rb
@@ -4,7 +4,7 @@ module Errors
include SimpleForm::Helpers::HasErrors
def error
- template.content_tag(error_tag, error_text, error_html_options) if has_errors?
+ enabled_error
end
def error_tag
@@ -29,6 +29,14 @@ def error_html_options
protected
+ def enabled_error
+ template.content_tag(error_tag, error_text, error_html_options) if has_errors?
+ end
+
+ def disabled_error
+ nil
+ end
+
def errors
@errors ||= (errors_on_attribute + errors_on_association).compact
end
View
10 lib/simple_form/components/hints.rb
@@ -2,9 +2,19 @@ module SimpleForm
module Components
module Hints
def hint
+ enabled_hint
+ end
+
+ private
+
+ def enabled_hint
template.content_tag(hint_tag, hint_text, hint_html_options) unless hint_text.blank?
end
+ def disabled_hint
+ nil
+ end
+
def hint_tag
options[:hint_tag] || SimpleForm.hint_tag
end
View
10 lib/simple_form/components/labels.rb
@@ -24,7 +24,7 @@ def translate_required_mark
end
def label
- @builder.label(label_target, label_text, label_html_options)
+ enabled_label
end
def label_text
@@ -43,6 +43,14 @@ def label_html_options
protected
+ def enabled_label
+ @builder.label(label_target, label_text, label_html_options)
+ end
+
+ def disabled_label
+ ""
+ end
+
def raw_label_text #:nodoc:
options[:label] || label_translation
end
View
8 lib/simple_form/components/placeholders.rb
@@ -2,16 +2,20 @@ module SimpleForm
module Components
module Placeholders
def placeholder
- nil # This components is disabled by default.
+ disabled_placeholder
end
private
- def active_placeholder
+ def enabled_placeholder
input_html_options[:placeholder] ||= placeholder_text if placeholder_present?
nil
end
+ def disabled_placeholder
+ nil
+ end
+
def placeholder_present?
options[:placeholder] != false && placeholder_text.present?
end
View
6 lib/simple_form/inputs/base.rb
@@ -22,7 +22,11 @@ class Base
# Enables certain components support to the given input.
def self.enable(*args)
- args.each { |m| alias_method m, :"active_#{m}" }
+ 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,
Please sign in to comment.
Something went wrong with that request. Please try again.