Sha256: a4c3ff0e812f9ad6780d13263893dcefcf1d5bdb769be1884ff6d947910eb0c5

Contents?: true

Size: 1.79 KB

Versions: 61

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require "primer/classify"

# See: https://github.com/rails/rails/pull/46666
ActionView::Helpers::Tags::Base.prepend(
  Module.new do
    def initialize(*args, **kwargs, &block)
      super

      return if defined?(@generate_error_markup)

      @generate_error_markup = @options.delete(:generate_error_markup) { true }
    end

    private

    def error_wrapping(html_tag)
      return html_tag unless @generate_error_markup

      # :nocov:
      super
      # :nocov:
    end
  end
)

module Primer
  module Forms
    # :nodoc:
    class Builder < ActionView::Helpers::FormBuilder
      alias primer_fields_for fields_for

      def label(method, text = nil, **options, &block)
        super(method, text, classify(options).merge(generate_error_markup: false), &block)
      end

      def check_box(method, options = {}, checked_value = 1, unchecked_value = 0, &block)
        super(
          method,
          classify(options).merge(generate_error_markup: false),
          checked_value,
          unchecked_value,
          &block
        )
      end

      def radio_button(*args, **options, &block)
        super(*args, classify(options).merge(generate_error_markup: false), &block)
      end

      def select(method, choices = nil, options = {}, html_options = {}, &block)
        super(method, choices, options.merge(generate_error_markup: false), classify(html_options), &block)
      end

      def text_field(*args, **options, &block)
        super(*args, classify(options).merge(generate_error_markup: false), &block)
      end

      def text_area(*args, **options, &block)
        super(*args, classify(options).merge(generate_error_markup: false), &block)
      end

      private

      def classify(options)
        Primer::Forms::Utils.classify(options)
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.23.0 lib/primer/forms/builder.rb
primer_view_components-0.19.0 lib/primer/forms/builder.rb
openproject-primer_view_components-0.22.2 lib/primer/forms/builder.rb
primer_view_components-0.18.2 lib/primer/forms/builder.rb
openproject-primer_view_components-0.22.1 lib/primer/forms/builder.rb
primer_view_components-0.18.1 lib/primer/forms/builder.rb
openproject-primer_view_components-0.22.0 lib/primer/forms/builder.rb
primer_view_components-0.18.0 lib/primer/forms/builder.rb
openproject-primer_view_components-0.21.0 lib/primer/forms/builder.rb
primer_view_components-0.17.0 lib/primer/forms/builder.rb
openproject-primer_view_components-0.20.0 lib/primer/forms/builder.rb
primer_view_components-0.16.1 lib/primer/forms/builder.rb
primer_view_components-0.16.0 lib/primer/forms/builder.rb
openproject-primer_view_components-0.19.0 lib/primer/forms/builder.rb
primer_view_components-0.15.1 lib/primer/forms/builder.rb
primer_view_components-0.15.0 lib/primer/forms/builder.rb
openproject-primer_view_components-0.18.1 lib/primer/forms/builder.rb
openproject-primer_view_components-0.17.1 lib/primer/forms/builder.rb
openproject-primer_view_components-0.17.0 lib/primer/forms/builder.rb
primer_view_components-0.14.0 lib/primer/forms/builder.rb