Skip to content

Allow to define multiple wrapper mappings #1632

Open
@JanStevens

Description

Environment

  • Ruby 2.5.3
  • Rails 5.2.2
  • Simple Form 4.1.0

Proposal

The current wrapper mappings allow to specify how every field type should be mapped and this allows to have a consistent style across your application. However there is a need to have additional styles / wrappers for different kinds of search inputs, a typical example is search forms. For example in our application we have Vertical Forms, using custom bootstrap wrapper mappings but for the search filters (using ransack) above our tables we would more like an inline style where labels are hidden by default.

Current solution is to always pass in the wrapper_mappings in the simple_form_tag but even with a helper method around it, this is a bit error prone. I propose to add the concept of wrapper sets (as originally proposed in #1229).

For backwards compatibility the default configuration would still be possible

config.wrapper_mappings = {
    boolean:       :custom_boolean,
    check_boxes:   :custom_collection,
    date:          :custom_multi_select,
    datetime:      :custom_multi_select,
    file:          :custom_file,
    radio_buttons: :custom_collection,
    range:         :custom_range,
    time:          :custom_multi_select,
    select:        :custom_multi_select
  }

Internally this will be set on wrapper_mappings[:default] and used across the board, advance usage could then also define a new set of wrappers

config.wrapper_mappings[:search] = {
    boolean:       :custom_boolean_search,
    check_boxes:   :custom_collection_search,
    date:          :custom_multi_select_search,
    datetime:      :custom_multi_select_search,
    file:          :custom_file_search,
    radio_buttons: :custom_collection_search,
    range:         :custom_range_search,
    time:          :custom_multi_select_search,
    select:        :custom_multi_select_search
  }

This could then be used in the form asfollowed

simple_form_for(animal, wrapper_mappings: :search)
OR
simple_form_for(animal, wrapper_set: :search)

I'm willing to spend some time on this if it will be accepted as a MR

Regards,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions