Skip to content
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

Running with Bootstrap 3 & 4 in the same app, insane or possible? #350

Open
prognostikos opened this issue Oct 25, 2021 · 3 comments
Open

Comments

@prognostikos
Copy link

We have a mature app using simple_form with Bootstrap 3. We are developing a new set of features where we would like to use Bootstrap 4 or maybe even 5 depending on when we launch the features, with the goal of eventually transitioning the old v3 views to use whatever new version we settle on.

Is there any suggested way of doing this? One option I guess would be to customize all of the wrappers in the generated simple_form bootstrap initializer (e.g. add a bs4_ prefix or something like that and then explicity add wrapper: :bs4_vertical_form or whatever in each call to simple form. I would like to avoid this if possible, but not if it's the only sane way.

I guess another option would be to remove the initializers and create two separate form builders and move all the initialization configuration code into the initialize method of each form builder. That's probably not great for performance but it may not be enough of an issue to matter.

Does anyone have any other ideas or suggestions? Thanks in advance.

@metade
Copy link

metade commented Sep 19, 2022

Hey @prognostikos, we're looking to do something similar, i.e. have an app running both Bootstrap 3 and 5 while we transition pages in version 3 to version 5.

Did you come up with a solution?

I've been scratching my head looking at https://github.com/heartcombo/simple_form/blob/main/lib/simple_form.rb#L287-L290 but as the configuration is defined on the SimpleForm module it's not easy to have multiple configurations running at the same time.

@prognostikos
Copy link
Author

@metade we ended up doing the second option - moving config out of initializers and into separate form builders. It doesn't seem to have much of an impact on performance.

It's not pretty, but here's what has worked:

class Bootstrap4FormBuilder < SimpleForm::FormBuilder
  def initialize(*)
    configure_boostrap4_wrappers
    super
    @object = convert_to_model(@object)
    @defaults = options[:defaults]
    @wrapper = SimpleForm.wrapper(options[:wrapper] || SimpleForm.default_wrapper)
  end

  def configure_boostrap4_wrappers
    # all of the config code from the initializers
  end
end

@metade
Copy link

metade commented Sep 19, 2022

Thank you @prognostikos - that leaves us plenty to think about!

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

No branches or pull requests

2 participants