Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default_builder configuration option #1796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@
# Defines validation classes to the input_field. By default it's nil.
# config.input_field_valid_class = 'is-valid'
# config.input_field_error_class = 'is-invalid'

# Defines the default form builder when more customization is needed.
# config.default_builder = 'SimpleForm::OtherCSSFramework::FormBuilder'
end
3 changes: 3 additions & 0 deletions lib/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ def self.configured? #:nodoc:
mattr_accessor :input_field_valid_class
@@input_field_valid_class = nil

mattr_accessor :default_builder
@@default_builder = 'SimpleForm::FormBuilder'

# Retrieves a given wrapper
def self.wrapper(name)
@@wrappers[name.to_s] or raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/action_view_extensions/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def simple_fields_for(*args, &block)
if self.class < ActionView::Helpers::FormBuilder
options[:builder] ||= self.class
else
options[:builder] ||= SimpleForm::FormBuilder
options[:builder] ||= SimpleForm.default_builder.constantize
end
fields_for(*args, options, &block)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/simple_form/action_view_extensions/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ActionViewExtensions
module FormHelper

def simple_form_for(record, options = {}, &block)
options[:builder] ||= SimpleForm::FormBuilder
options[:builder] ||= SimpleForm.default_builder.constantize
options[:html] ||= {}
unless options[:html].key?(:novalidate)
options[:html][:novalidate] = !SimpleForm.browser_validations
Expand All @@ -30,7 +30,7 @@ def simple_form_for(record, options = {}, &block)

def simple_fields_for(record_name, record_object = nil, options = {}, &block)
options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
options[:builder] ||= SimpleForm::FormBuilder
options[:builder] ||= SimpleForm.default_builder.constantize

with_simple_form_field_error_proc do
fields_for(record_name, record_object, options, &block)
Expand Down