Convert disabled to a component.
This commit is contained in:
parent
3af639660d
commit
fcd049adc6
|
@ -149,7 +149,9 @@ module SimpleForm
|
|||
end
|
||||
|
||||
wrappers :class => :input, :error_class => :field_with_errors do |b|
|
||||
b.use :disabled
|
||||
b.use :placeholder
|
||||
|
||||
b.use :label_input
|
||||
b.use :hint, :tag => :span, :class => :hint
|
||||
b.use :error, :tag => :span, :class => :error
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module SimpleForm
|
||||
module Components
|
||||
autoload :Disabled, 'simple_form/components/disabled'
|
||||
autoload :Errors, 'simple_form/components/errors'
|
||||
autoload :Hints, 'simple_form/components/hints'
|
||||
autoload :LabelInput, 'simple_form/components/label_input'
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
module SimpleForm
|
||||
module Components
|
||||
module Disabled
|
||||
def disabled
|
||||
if has_disabled?
|
||||
input_html_classes << 'disabled'
|
||||
input_html_options[:disabled] = true
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def has_disabled?
|
||||
options[:disabled] == true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
alias :enabled_disabled :disabled
|
||||
|
||||
def disabled_disabled
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,6 @@ module SimpleForm
|
|||
autoload :Pattern, 'simple_form/helpers/pattern'
|
||||
autoload :Validators, 'simple_form/helpers/validators'
|
||||
autoload :Required, 'simple_form/helpers/required'
|
||||
autoload :Disabled, 'simple_form/helpers/disabled'
|
||||
autoload :Readonly, 'simple_form/helpers/readonly'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
module SimpleForm
|
||||
module Helpers
|
||||
module Disabled
|
||||
private
|
||||
|
||||
def disabled_class
|
||||
'disabled' if has_disabled?
|
||||
end
|
||||
|
||||
def has_disabled?
|
||||
options[:disabled] == true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,12 +4,12 @@ module SimpleForm
|
|||
extend I18nCache
|
||||
|
||||
include SimpleForm::Helpers::Required
|
||||
include SimpleForm::Helpers::Disabled
|
||||
include SimpleForm::Helpers::Readonly
|
||||
include SimpleForm::Helpers::Validators
|
||||
include SimpleForm::Helpers::Maxlength
|
||||
include SimpleForm::Helpers::Pattern
|
||||
|
||||
include SimpleForm::Components::Disabled
|
||||
include SimpleForm::Components::Errors
|
||||
include SimpleForm::Components::Hints
|
||||
include SimpleForm::Components::LabelInput
|
||||
|
@ -25,7 +25,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
attr_reader :attribute_name, :column, :input_type, :reflection,
|
||||
:options, :input_html_options
|
||||
:options, :input_html_options, :input_html_classes
|
||||
|
||||
delegate :template, :object, :object_name, :lookup_model_names, :lookup_action, :to => :@builder
|
||||
|
||||
|
@ -37,9 +37,13 @@ module SimpleForm
|
|||
@reflection = options.delete(:reflection)
|
||||
@options = options
|
||||
@required = calculate_required
|
||||
|
||||
# Notice that html_options_for receives a reference to input_html_classes.
|
||||
# This means that classes added dynamically to input_html_classes will
|
||||
# still propagate to input_html_options.
|
||||
@input_html_classes = [input_type, required_class, readonly_class].compact
|
||||
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
||||
o[:required] = true if has_required?
|
||||
o[:disabled] = true if has_disabled?
|
||||
o[:readonly] = true if has_readonly?
|
||||
o[:autofocus] = true if has_autofocus?
|
||||
end
|
||||
|
@ -53,10 +57,6 @@ module SimpleForm
|
|||
options
|
||||
end
|
||||
|
||||
def input_html_classes
|
||||
[input_type, required_class, disabled_class, readonly_class].compact
|
||||
end
|
||||
|
||||
def has_autofocus?
|
||||
options[:autofocus]
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ module SimpleForm
|
|||
# Retrieve options for the given namespace from the options hash
|
||||
def html_options_for(namespace, extra)
|
||||
html_options = options[:"#{namespace}_html"] || {}
|
||||
html_options[:class] = (extra << html_options[:class]).join(' ').strip if extra.present?
|
||||
html_options[:class] = (extra << html_options[:class]) if extra.present?
|
||||
html_options
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue