diff --git a/CHANGELOG.md b/CHANGELOG.md index 9166533..86830f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Default `form_with` extension's `:model` option to `false` instead of `nil` [@seanpdoyle] + ## 1.9.0 * Added support for `form_with` [@DialBird] diff --git a/lib/html5_validators/action_view/form_helpers.rb b/lib/html5_validators/action_view/form_helpers.rb index 952c048..52c132e 100644 --- a/lib/html5_validators/action_view/form_helpers.rb +++ b/lib/html5_validators/action_view/form_helpers.rb @@ -13,7 +13,7 @@ def form_for(record, options = {}, &block) end if Rails::VERSION::STRING >= '5.1' - def form_with(model: nil, scope: nil, url: nil, format: nil, **options) + def form_with(model: false, scope: nil, url: nil, format: nil, **options) if model && model.respond_to?(:auto_html5_validation=) if !Html5Validators.enabled || (options[:auto_html5_validation] == false) model.auto_html5_validation = false diff --git a/test/fake_app.rb b/test/fake_app.rb index d1097e2..ebed084 100644 --- a/test/fake_app.rb +++ b/test/fake_app.rb @@ -32,6 +32,7 @@ class Html5ValidatorsTestApp < Rails::Application get :new_with_required_false end end + resources :forms, only: [:new, :create] end # models @@ -213,6 +214,15 @@ def new_with_required_false ERB end end +class FormsController < ApplicationController + def new + render inline: <<-ERB +<%= form_with url: forms_path, id: 'form_with' do |f| %> +<%= f.button %> +<% end %> + ERB + end +end # helpers module ApplicationHelper; end diff --git a/test/features/active_model_validation_test.rb b/test/features/active_model_validation_test.rb index 2154b2d..8e2d09d 100644 --- a/test/features/active_model_validation_test.rb +++ b/test/features/active_model_validation_test.rb @@ -125,4 +125,13 @@ class ActiveModelValidationTest < ActionDispatch::IntegrationTest end end end + + if Rails::VERSION::STRING >= '5.1' + sub_test_case 'without model' do + test 'new form' do + visit '/forms/new' + assert page.has_css? '#form_with button' + end + end + end end