From dc3fd0922c264afbeb45534edd2ec02419a875cc Mon Sep 17 00:00:00 2001 From: Kai Schlamp Date: Fri, 3 Jun 2011 22:54:19 +0200 Subject: [PATCH] Fixes #263 and added some documentation for the form specfic novalidate feature. --- README.rdoc | 4 ++++ .../action_view_extensions/form_helper.rb | 2 +- test/action_view_extensions/form_helper_test.rb | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 7dd16c90..73f8d618 100644 --- a/README.rdoc +++ b/README.rdoc @@ -442,6 +442,10 @@ If you want to have all other HTML 5 features, such as the new field types, you This option adds a new `novalidate` property to the form, instructing it to skip all HTML 5 validation. The inputs will still be generated with the required and other attributes, that might help you to use some generic javascript validation. +You can also add `novalidate` to a specific form by setting the option on the form itself: + + <%= simple_form_for(resource, :html => {:novalidate => true}) do |form| %> + Please notice that any of the configurations above will disable the `placeholder` component, which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute fine, and if they aren't, any plugin you use would take of using the placeholder attribute to do it. However, you can disable it if you want, by removing the placeholder component from the components list in SimpleForm configuration file. == Configuration diff --git a/lib/simple_form/action_view_extensions/form_helper.rb b/lib/simple_form/action_view_extensions/form_helper.rb index 31ac4d2a..f32f6c65 100644 --- a/lib/simple_form/action_view_extensions/form_helper.rb +++ b/lib/simple_form/action_view_extensions/form_helper.rb @@ -40,7 +40,7 @@ module SimpleForm else dom_class(record_or_name_or_array) end options[:html] ||= {} - options[:html][:novalidate] = !SimpleForm.browser_validations + options[:html][:novalidate] = !SimpleForm.browser_validations if options[:html][:novalidate].nil? options[:html][:class] = "\#{SimpleForm.form_class} \#{css_class} \#{options[:html][:class]}".strip with_custom_field_error_proc do diff --git a/test/action_view_extensions/form_helper_test.rb b/test/action_view_extensions/form_helper_test.rb index 63e74a24..b8e76d75 100644 --- a/test/action_view_extensions/form_helper_test.rb +++ b/test/action_view_extensions/form_helper_test.rb @@ -25,6 +25,18 @@ class FormHelperTest < ActionView::TestCase end end + test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do + concat(simple_form_for(:user, :html => {:novalidate => true}) do |f| end) + assert_select 'form[novalidate="novalidate"]' + end + + test 'a form specific enabled validation option should override the disabled browser validation configuration option' do + swap SimpleForm, :browser_validations => false do + concat(simple_form_for(:user, :html => {:novalidate => false}) do |f| end) + assert_no_select 'form[novalidate]' + end + end + test 'simple form should add object name as css class to form when object is not present' do concat(simple_form_for(:user) do |f| end) assert_select 'form.simple_form.user'