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

36 lines
No EOL
847 B
Ruby

module SimpleForm
module Helpers
module Required
private
def attribute_required?
@required
end
def calculate_required
if !options[:required].nil?
options[:required]
elsif has_validators?
(attribute_validators + reflection_validators).any? do |v|
v.kind == :presence && valid_validator?(v)
end
else
attribute_required_by_default?
end
end
# Whether this input is valid for HTML 5 required attribute.
def has_required?
attribute_required? && SimpleForm.html5 && SimpleForm.browser_validations
end
def attribute_required_by_default?
SimpleForm.required_by_default
end
def required_class
attribute_required? ? :required : :optional
end
end
end
end