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
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ jobs:
rails_version: [edge, '8.0', '7.2', '7.1', '7.0', '6.1']

include:
- ruby_version: '3.2'
activemodel_version: '8.0'

- ruby_version: '3.1'
activemodel_version: '7.2'
- ruby_version: '3.1'
activemodel_version: '7.1'
- ruby_version: '3.1'
activemodel_version: '7.0'

Expand Down
11 changes: 10 additions & 1 deletion lib/html5_validators/action_view/form_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ def form_for(record, options = {}, &block)
super
end

if Rails::VERSION::STRING >= '5.1'
if Rails::VERSION::STRING >= '7.2'
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
end
end
super
end
elsif Rails::VERSION::STRING >= '5.1'
def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
if model && model.respond_to?(:auto_html5_validation=)
if !Html5Validators.enabled || (options[:auto_html5_validation] == false)
Expand Down
13 changes: 13 additions & 0 deletions test/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Html5ValidatorsTestApp < Rails::Application
get :new_with_required_false
end
end

if Rails::VERSION::STRING >= '5.1'
resources :search, only: [:index]
end
end

# models
Expand Down Expand Up @@ -213,6 +217,15 @@ def new_with_required_false
ERB
end
end
class SearchController < ApplicationController
def index
render inline: <<-ERB
<%= form_with url: '/search', id: 'form_with' do |f| %>
<%= f.search_field :query, id: 'query' %>
<% end %>
ERB
end
end

# helpers
module ApplicationHelper; end
14 changes: 14 additions & 0 deletions test/features/without_model_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'test_helper'

class WithoutModelTest < ActionDispatch::IntegrationTest
if Rails::VERSION::STRING >= '5.1'
sub_test_case 'without model' do
test 'form_with' do
visit '/search'
assert page.has_css? '#form_with input#query'
end
end
end
end