and added some documentation for the form specfic novalidate feature.
This commit is contained in:
Kai Schlamp 2011-06-03 22:54:19 +02:00
parent 9bd9e9821b
commit dc3fd0922c
3 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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'