Skip to content

Commit

Permalink
monkey patch formtastic to support latest country_select
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Dec 2, 2024
1 parent 47c236f commit 8f5f764
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ gem 'aws-sdk-s3' # Talk to the catalog
# Admin Dashboard
gem 'activeadmin'
gem 'mission_control-jobs' # Jobs dashboard
gem 'country_select' # , '~> 8.0' # 9.0 breaks active admin
gem 'country_select'

# Graphql
gem 'graphiql-rails' # , '1.8.0' # https://github.com/rmosolgo/graphiql-rails/issues/106
Expand Down
25 changes: 25 additions & 0 deletions lib/monkeypatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,28 @@ class RecordResponse < Base
# Make zeitwork happy
module Monkeypatch
end

# NOTE: Formtastic 5 doesn't support latest country_select gem
# https://github.com/formtastic/formtastic/issues/1381
module Formtastic
module Inputs
class CountryInput
include Base

CountrySelectPluginMissing = Class.new(StandardError)

def to_html
raise CountrySelectPluginMissing, 'To use the :country input, please install a country_select plugin, like this one: https://github.com/stefanpenner/country_select' unless builder.respond_to?(:country_select)

input_wrapping do
label_html <<
builder.country_select(method, input_options.reverse_merge(priority_countries:), input_html_options)
end
end

def priority_countries
options[:priority_countries] || builder.priority_countries
end
end
end
end

0 comments on commit 8f5f764

Please sign in to comment.