Skip to content

Commit 3bf35c9

Browse files
committed
Extract inject_numericality_fields method
1 parent a14cc22 commit 3bf35c9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/html5_validators/action_view/form_helpers.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def inject_maxlength_field
1111
@options["maxlength"] ||= @options[:maxlength] || object.class.attribute_maxlength(@method_name)
1212
end
1313
end
14+
15+
def inject_numericality_fields
16+
if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
17+
@options["max"] ||= @options["max"] || @options[:max] || object.class.attribute_max(@method_name)
18+
@options["min"] ||= @options["min"] || @options[:min] || object.class.attribute_min(@method_name)
19+
end
20+
end
1421
end
1522
end
1623

@@ -38,11 +45,8 @@ class TextField
3845
def render_with_html5_attributes
3946
inject_required_field
4047
inject_maxlength_field
48+
inject_numericality_fields
4149

42-
if object.class.ancestors.include?(ActiveModel::Validations) && (object.auto_html5_validation != false) && (object.class.auto_html5_validation != false)
43-
@options["max"] ||= @options["max"] || @options[:max] || object.class.attribute_max(@method_name)
44-
@options["min"] ||= @options["min"] || @options[:min] || object.class.attribute_min(@method_name)
45-
end
4650
render_without_html5_attributes
4751
end
4852
alias_method_chain :render, :html5_attributes

0 commit comments

Comments
 (0)