Move required to html5 component.
This commit is contained in:
parent
6e4431f7c6
commit
2d41fafe9b
|
@ -5,23 +5,19 @@ SimpleForm.setup do |config|
|
|||
# add your own to the stack. The options given to the wrappers method
|
||||
# are used to wrap the whole input.
|
||||
config.wrappers :class => :input, :error_class => :field_with_errors do |b|
|
||||
## Configuration
|
||||
# Determines whether to use HTML5 inputs (:email, :url, :search, :tel).
|
||||
b.use :html5
|
||||
|
||||
## Extensions
|
||||
# Determines whether to use HTML5 (:email, :url, :search, :tel) and required attributes
|
||||
b.use :html5
|
||||
# Calculates maxlength from length validations automatically for string inputs
|
||||
# b.use :maxlength
|
||||
# Calculates pattern from format validations automatically for string inputs
|
||||
# b.use :pattern
|
||||
# Calculates min and max from length validations automatically for numeric inputs
|
||||
# b.use :min_max
|
||||
# Calculates readonly automatically from the readonly attributes
|
||||
# Calculates readonly automatically from readonly attributes
|
||||
# b.use :readonly
|
||||
# Calculates placeholders automatically from I18n
|
||||
b.use :placeholder
|
||||
# Calculates required from presence validations automatically
|
||||
b.use :required
|
||||
|
||||
## Inputs
|
||||
b.use :label_input
|
||||
|
|
|
@ -147,7 +147,6 @@ module SimpleForm
|
|||
b.use :min_max
|
||||
b.use :maxlength
|
||||
b.use :placeholder
|
||||
b.use :required
|
||||
b.use :pattern
|
||||
b.use :readonly
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ module SimpleForm
|
|||
autoload :Maxlength, 'simple_form/components/maxlength'
|
||||
autoload :Pattern, 'simple_form/components/pattern'
|
||||
autoload :Placeholders, 'simple_form/components/placeholders'
|
||||
autoload :Required, 'simple_form/components/required'
|
||||
autoload :Readonly, 'simple_form/components/readonly'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,17 @@ module SimpleForm
|
|||
|
||||
def html5
|
||||
@html5 = true
|
||||
input_html_options[:required] = true if has_required?
|
||||
nil
|
||||
end
|
||||
|
||||
def html5?
|
||||
@html5
|
||||
end
|
||||
|
||||
def has_required?
|
||||
required_field?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,9 +3,9 @@ module SimpleForm
|
|||
# Needs to be enabled in order to do automatic lookups.
|
||||
module Readonly
|
||||
def readonly
|
||||
if readonly_attribute?
|
||||
if readonly_attribute? && !has_readonly?
|
||||
input_html_options[:readonly] ||= true
|
||||
add_readonly_class!
|
||||
input_html_classes << :readonly
|
||||
end
|
||||
|
||||
nil
|
||||
|
@ -18,10 +18,6 @@ module SimpleForm
|
|||
object.persisted? &&
|
||||
object.class.readonly_attributes.include?(attribute_name)
|
||||
end
|
||||
|
||||
def add_readonly_class!
|
||||
input_html_classes.push(:readonly).compact! unless input_html_classes.include?(:readonly)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
module SimpleForm
|
||||
module Components
|
||||
module Required
|
||||
def required
|
||||
input_html_options[:required] = true if has_required?
|
||||
nil
|
||||
end
|
||||
|
||||
def has_required?
|
||||
required_field?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def disabled_class
|
||||
"disabled" if has_disabled?
|
||||
:disabled if has_disabled?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,6 @@ module SimpleForm
|
|||
include SimpleForm::Components::Maxlength
|
||||
include SimpleForm::Components::Pattern
|
||||
include SimpleForm::Components::Placeholders
|
||||
include SimpleForm::Components::Required
|
||||
include SimpleForm::Components::Readonly
|
||||
|
||||
attr_reader :attribute_name, :column, :input_type, :reflection,
|
||||
|
|
Loading…
Reference in New Issue