Added config option to disable browser validations on all form elements.
This commit is contained in:
parent
55e94b88c4
commit
abf48a740d
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue