From 72cfbc5bffa9c65cedc6b8c4d4d20b0e398495eb Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 5 Apr 2011 21:23:40 -0300 Subject: [PATCH] Tidy up last patch tests and update changelog --- CHANGELOG.rdoc | 1 + .../simple_form/templates/simple_form.rb | 6 +++--- lib/simple_form.rb | 9 ++++----- test/action_view_extensions/form_helper_test.rb | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index a19ebbd6..b9e68537 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -7,6 +7,7 @@ * Add slim form generator (by github.com/fagiani) * Add form_class configuration option (by github.com/fagiani) * Default step of "any" for number input with non integer attributes (by github.com/fedesoria) + * Add option to disable HTML5 browser validations on all forms (by github.com/coryschires) * bug fix * Fix for file attributes automatic detection, to work with virtual attributes diff --git a/lib/generators/simple_form/templates/simple_form.rb b/lib/generators/simple_form/templates/simple_form.rb index dee88fb6..77f26e9a 100644 --- a/lib/generators/simple_form/templates/simple_form.rb +++ b/lib/generators/simple_form/templates/simple_form.rb @@ -4,9 +4,6 @@ SimpleForm.setup do |config| # any of them, change the order, or even add your own components to the stack. # config.components = [ :placeholder, :label_input, :hint, :error ] - # Allow browsers to use default validations. - # config.disable_browser_validations = false - # Default tag used on hints. # config.hint_tag = :span @@ -64,6 +61,9 @@ SimpleForm.setup do |config| # Whether attributes are required by default (or not). Default is true. # config.required_by_default = true + # Tell browsers whether to use default HTML5 validations (novalidate option). Default is enabled. + # config.disable_browser_validations = false + # Custom mappings for input types. This should be a hash containing a regexp # to match as key, and the input type that will be used when the field name # matches the regexp as value. diff --git a/lib/simple_form.rb b/lib/simple_form.rb index 5698475a..37495b79 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -11,11 +11,6 @@ module SimpleForm autoload :Inputs, 'simple_form/inputs' autoload :MapType, 'simple_form/map_type' - - # Allow browsers to use default validations. - mattr_accessor :disable_browser_validations - @@disable_browser_validations = false - # Default tag used on hints. mattr_accessor :hint_tag @@hint_tag = :span @@ -96,6 +91,10 @@ module SimpleForm mattr_accessor :required_by_default @@required_by_default = true + # Tell browsers whether to use default HTML5 validations. + mattr_accessor :disable_browser_validations + @@disable_browser_validations = false + # Collection of methods to detect if a file type was given. mattr_accessor :file_methods @@file_methods = [ :mounted_as, :file?, :public_filename ] diff --git a/test/action_view_extensions/form_helper_test.rb b/test/action_view_extensions/form_helper_test.rb index ace62113..083548fb 100644 --- a/test/action_view_extensions/form_helper_test.rb +++ b/test/action_view_extensions/form_helper_test.rb @@ -13,16 +13,16 @@ class FormHelperTest < ActionView::TestCase assert_select 'form.simple_form' end - test 'simple form should not use default browser validations if specified in the configuration options' do - SimpleForm.disable_browser_validations = true + test 'simple form should use default browser validations by default' do concat(simple_form_for(:user) do |f| end) - assert_select 'form[novalidate="novalidate"]' + assert_no_select 'form[novalidate]' end - test 'simple form should use default browser validations by default' do - SimpleForm.disable_browser_validations = false - concat(simple_form_for(:user) do |f| end) - assert_select 'form[novalidate="novalidate"]', false + test 'simple form should not use default browser validations if specified in the configuration options' do + swap SimpleForm, :disable_browser_validations => true do + concat(simple_form_for(:user) do |f| end) + assert_select 'form[novalidate="novalidate"]' + end end test 'simple form should add object name as css class to form when object is not present' do