1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Provide enable/disable API.

This commit is contained in:
José Valim 2011-09-03 12:55:53 +02:00
parent ff646641ed
commit f50e5bdaea
5 changed files with 39 additions and 5 deletions

View file

@ -4,7 +4,7 @@ module SimpleForm
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 @@ module SimpleForm
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 file

@ -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 file

@ -24,7 +24,7 @@ module SimpleForm
end
def label
@builder.label(label_target, label_text, label_html_options)
enabled_label
end
def label_text
@ -43,6 +43,14 @@ module SimpleForm
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 file

@ -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 file

@ -22,7 +22,11 @@ module SimpleForm
# 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,