Added config option to disable browser validations on all form elements.

This commit is contained in:
Cory Schires 2011-04-02 22:26:37 +08:00 committed by Carlos Antonio da Silva
parent 55e94b88c4
commit abf48a740d
4 changed files with 21 additions and 0 deletions

View File

@ -4,6 +4,9 @@ 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

View File

@ -11,6 +11,11 @@ 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

View File

@ -40,6 +40,7 @@ module SimpleForm
else dom_class(record_or_name_or_array)
end
options[:html] ||= {}
options[:html][:novalidate] = SimpleForm.disable_browser_validations
options[:html][:class] = "\#{SimpleForm.form_class} \#{css_class} \#{options[:html][:class]}".strip
with_custom_field_error_proc do

View File

@ -13,6 +13,18 @@ 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
concat(simple_form_for(:user) do |f| end)
assert_select 'form[novalidate="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
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'