-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to define multiple wrapper mappings #1632
Comments
I'm ok with this proposal. @rafaelfranca any thoughts? |
One additional thought on this: If you have multiple form wrappers defined according to the proposal of @JanStevens it would be still necessary to select the wrapper mapping every time I render a form with an explicit wrapper instead of setting a default once when the form wrapper is defined. I think it would be helpful to end up with a result like this: config.wrappers :my_special_form do |b|
b.wrapper_mapping :my_special_mapping
b.use :input
# ...
end
config.wrapper_mappings[:my_special_mapping] = {
boolean: :my_special_boolean,
# ....
} Then when using the form in the view like this it would know which form wrapper to use and also automatically which mapping to use for this wrapper: simple_form_for(animal, wrapper: :my_special_form) |
Multiple wrapper mappings would be really helpful. @JanStevens Any news on this issue? Are you still planning to submit a pull request? |
Sadly no, I've moved on and not actively working with rails anymore 😬 |
As a quick workaround, you can create a custom simple_form helper and add some logic there : # app/helpers/application_helper.rb
module ApplicationHelper
def my_simple_form_for(record, options, &block)
if options[:wrapper] == :search && options[:wrapper_mappings].nil?
options[:wrapper_mappings] = {
boolean: :custom_boolean_search,
check_boxes: :custom_collection_search,
.....
}
end
simple_form_for(record, options, &block)
end
end |
Anyone working on this? I might take a stab otherwise |
compatible config as per issue/suggestion heartcombo#1632
I did a stab... It's pretty basic really. |
It could be so helpful if this PR could be merged because it could be very useful in many use cases. On my side, I want to migrate from bootstrap to tailwind with specific simple form wrappers and this PR permits to improve gem uses. |
Environment
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 thesimple_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
Internally this will be set on
wrapper_mappings[:default]
and used across the board, advance usage could then also define a new set of wrappersThis could then be used in the form asfollowed
I'm willing to spend some time on this if it will be accepted as a MR
Regards,
The text was updated successfully, but these errors were encountered: