Sha256: e429c0df6c430ad319095798b2c8763aa8bec1d6feadbc193b48a14e6cdd8fd8

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

require_relative 'helpers/nested_form'

module BootstrapForm
  module Helper
    include ::BootstrapForm::Helpers::NestedForm

    def bootstrap_form_for(object, options = {}, &block)
      options.reverse_merge!({builder: BootstrapForm::FormBuilder})

      options[:html] ||= {}
      options[:html][:role] ||= 'form'

      layout = case options[:layout]
        when :inline
          "form-inline"
        when :horizontal
          "form-horizontal"
      end

      if layout
        options[:html][:class] = [options[:html][:class], layout].compact.join(" ")
      end

      temporarily_disable_field_error_proc do
        form_for(object, options, &block)
      end
    end

    def bootstrap_form_tag(options = {}, &block)
      options[:acts_like_form_tag] = true

      bootstrap_form_for("", options, &block)
    end

    def temporarily_disable_field_error_proc
      original_proc = ActionView::Base.field_error_proc
      ActionView::Base.field_error_proc = proc { |input, instance| input }
      yield
    ensure
      ActionView::Base.field_error_proc = original_proc
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bootstrap_form-2.7.0 lib/bootstrap_form/helper.rb
bootstrap_form-2.6.0 lib/bootstrap_form/helper.rb
bootstrap_form-2.5.3 lib/bootstrap_form/helper.rb
bootstrap_form-2.5.2 lib/bootstrap_form/helper.rb
bootstrap_form-2.5.1 lib/bootstrap_form/helper.rb
bootstrap_form-2.5.0 lib/bootstrap_form/helper.rb
bootstrap_form-2.4.0 lib/bootstrap_form/helper.rb
bootstrap_form-2.3.0 lib/bootstrap_form/helper.rb
bootstrap_form-2.2.0 lib/bootstrap_form/helper.rb