Permalink
Browse files
Provide enable/disable API.
- Loading branch information...
|
@@ -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
|
|
|
|
@@ -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
|
|
|
|
@@ -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
|
|
|
|
@@ -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
|
|
|
|
@@ -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,
|
|
|
0 comments on commit
f50e5bd