Sha256: c533737a979af21b902babca7457acae8dace554784eeceffea8214a263edae7

Contents?: true

Size: 1005 Bytes

Versions: 20

Compression:

Stored size: 1005 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  module Forms
    class Builder < SimpleForm::FormBuilder
      # Renders a simple_form input, but uses input alchemy_wrapper
      #
      def input(attribute_name, options = {}, &block)
        options[:wrapper] = :alchemy

        if object.respond_to?(:attribute_fixed?) && object.attribute_fixed?(attribute_name)
          options[:disabled] = true
          options[:input_html] = options.fetch(:input_html, {}).merge(
            "data-alchemy-tooltip" => Alchemy.t(:attribute_fixed, attribute: attribute_name),
          )
        end

        super
      end

      # Renders a button tag wrapped in a div with 'submit' class.
      #
      def submit(label, options = {})
        options = {
          wrapper_html: {class: "submit"},
        }.update(options)
        template.content_tag("div", options.delete(:wrapper_html)) do
          template.content_tag("button", label, options.delete(:input_html))
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
alchemy_cms-5.3.8 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.7 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.6 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.5 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.4 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.3 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.2 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.1 lib/alchemy/forms/builder.rb
alchemy_cms-5.3.0 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.7 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.6 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.5 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.4 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.3 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.2 lib/alchemy/forms/builder.rb
alchemy_cms-6.0.0.b1 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.1 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.0 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.0.rc1 lib/alchemy/forms/builder.rb
alchemy_cms-5.2.0.b1 lib/alchemy/forms/builder.rb