@@ -4,8 +4,8 @@ module Helpers
44 module FormHelper
55 def form_for_with_auto_html5_validation_option ( record , options = { } , &proc )
66 if record . respond_to? ( :auto_html5_validation= )
7- if ! Html5Validators . enabled || ( options [ :auto_html5_validation ] == false )
8- record . auto_html5_validation = false
7+ if options . key? ( :auto_html5_validation )
8+ record . auto_html5_validation = options [ :auto_html5_validation ]
99 end
1010 end
1111 form_for_without_auto_html5_validation_option record , options , &proc
@@ -15,39 +15,35 @@ def form_for_with_auto_html5_validation_option(record, options = {}, &proc)
1515
1616 class InstanceTag
1717 def to_input_field_tag_with_html5_attributes ( field_type , options = { } )
18- if object . class . ancestors . include? ( ActiveModel ::Validations ) && ( object . auto_html5_validation != false ) && ( object . class . auto_html5_validation != false )
19- options [ "required" ] ||= object . class . attribute_required? ( method_name )
20- options [ "maxlength" ] ||= object . class . attribute_maxlength ( method_name )
21- options [ "minlength" ] ||= object . class . attribute_minlength ( method_name )
22- options [ "max" ] ||= object . class . attribute_max ( method_name )
23- options [ "min" ] ||= object . class . attribute_min ( method_name )
24- end
18+ options [ "required" ] ||= object . class . attribute_required? ( method_name ) if Html5Validators . validation_enabled? ( :required , object )
19+ options [ "maxlength" ] ||= object . class . attribute_maxlength ( method_name ) if Html5Validators . validation_enabled? ( :maxlength , object )
20+ options [ "minlength" ] ||= object . class . attribute_minlength ( method_name ) if Html5Validators . validation_enabled? ( :minlength , object )
21+ options [ "max" ] ||= object . class . attribute_max ( method_name ) if Html5Validators . validation_enabled? ( :max , object )
22+ options [ "min" ] ||= object . class . attribute_min ( method_name ) if Html5Validators . validation_enabled? ( :min , object )
23+
2524 to_input_field_tag_without_html5_attributes field_type , options
2625 end
2726 alias_method_chain :to_input_field_tag , :html5_attributes
2827
2928 def to_text_area_tag_with_html5_attributes ( options = { } )
30- if object . class . ancestors . include? ( ActiveModel ::Validations ) && ( object . auto_html5_validation != false ) && ( object . class . auto_html5_validation != false )
31- options [ "required" ] ||= object . class . attribute_required? ( method_name )
32- options [ "maxlength" ] ||= object . class . attribute_maxlength ( method_name )
33- options [ "minlength" ] ||= object . class . attribute_minlength ( method_name )
34- end
29+ options [ "required" ] ||= object . class . attribute_required? ( method_name ) if Html5Validators . validation_enabled? ( :required , object )
30+ options [ "maxlength" ] ||= object . class . attribute_maxlength ( method_name ) if Html5Validators . validation_enabled? ( :maxlength , object )
31+ options [ "minlength" ] ||= object . class . attribute_minlength ( method_name ) if Html5Validators . validation_enabled? ( :minlength , object )
32+
3533 to_text_area_tag_without_html5_attributes options
3634 end
3735 alias_method_chain :to_text_area_tag , :html5_attributes
3836
3937 def to_radio_button_tag_with_html5_attributes ( tag_value , options = { } )
40- if object . class . ancestors . include? ( ActiveModel ::Validations ) && ( object . auto_html5_validation != false ) && ( object . class . auto_html5_validation != false )
41- options [ "required" ] ||= object . class . attribute_required? ( method_name )
42- end
38+ options [ "required" ] ||= object . class . attribute_required? ( method_name ) if Html5Validators . validation_enabled? ( :required , object )
39+
4340 to_radio_button_tag_without_html5_attributes tag_value , options
4441 end
4542 alias_method_chain :to_radio_button_tag , :html5_attributes
4643
4744 def to_check_box_tag_with_html5_attributes ( options = { } , checked_value = "1" , unchecked_value = "0" )
48- if object . class . ancestors . include? ( ActiveModel ::Validations ) && ( object . auto_html5_validation != false ) && ( object . class . auto_html5_validation != false )
49- options [ "required" ] ||= object . class . attribute_required? ( method_name )
50- end
45+ options [ "required" ] ||= object . class . attribute_required? ( method_name ) if Html5Validators . validation_enabled? ( :required , object )
46+
5147 to_check_box_tag_without_html5_attributes options , checked_value , unchecked_value
5248 end
5349 alias_method_chain :to_check_box_tag , :html5_attributes
0 commit comments