Commit Graph

1 Commits

Author SHA1 Message Date
Felipe Renan b12ad4abc4 Add API to register custom components
With this API, Simple Form will be possible to add custom components.
Methods defined in a component will be exposed to be used in the
wrapper as Simple::Components

Examples

  # The application needs to tell where the components will be.
  Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }

  # Create a custom component in the path specified above.
  # lib/components/input_group_component.rb
  module InpoutGroupComponent
    def preprend
      ...
    end

    def append
      ...
    end
  end

  SimpleForm.setup do |config|
    # Create a wrapper using the custom component.
    config.wrappers :input_group, tag: :div, error_class: :error do |b|
      b.use :label
      b.optional :prepend
      b.use :input
      b.use :append
    end
  end

  # Using the custom component in the form.
  <%= simple_form_for @blog, wrapper: input_group do |f| %>
    <%= f.input :title, prepend: true %>
  <% end %>
2018-03-15 21:27:45 -03:00