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/required_helpers.rb

27 lines
803 B
Ruby
Raw Normal View History

module SimpleForm
module RequiredHelpers
2009-12-10 12:57:24 -05:00
# Attribute is always required, unless the user has defined the opposite.
def attribute_required?
2009-12-10 08:23:48 -05:00
options[:required] != false
end
def required_class
attribute_required? ? :required : :optional
end
2009-12-10 12:57:24 -05:00
# Creates default required classes for attributes, such as .string and
# .decimal, based on input type, and required class
def default_css_classes(merge_class=nil)
2009-12-10 08:23:48 -05:00
"#{input_type} #{required_class} #{merge_class}".strip
end
2009-12-10 12:57:24 -05:00
# When components may be required, default component html options always
# must include default css classes.
def component_html_options
html_options = super
html_options[:class] = default_css_classes(html_options[:class])
html_options
end
end
2009-12-10 12:57:24 -05:00
end