Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/html5_validators/action_view/form_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Html5ValidatorsTestApp < Rails::Application
get :new_with_required_false
end
end
resources :forms, only: [:new, :create]
end

# models
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/features/active_model_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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