mjbellantoni / formtastic-bootstrap

Formtastic form builder to generate Twitter Bootstrap-friendly markup.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Formtastic is changing how to namespace inputs

mikz opened this issue · comments

Hi,

there is formtastic pull request formtastic/formtastic#1063 that should be merged before the end of the year (hope).

It changes how formtastic looks up inputs/action classes. I already tried how that would work for activeadmin in mikz/activeadmin@3d933a3 and it worked great.

So please if you have any feedback, write it here or in the formtastic/formtastic#1063.

The changes were merged and released as 3.1. This behaviour will be default and only supported in 4.0.

Thanks for the heads up! I'll keep this ticket open until we're able to handle the new mechanism.

formtastic bootstrap 3.0.0 doesnt work well with formtastic 3.1.2 , anyone succeeded to make it works ?

thanks

@sodabrew any sense of how big of a change this is to support? I'd be happy to work towards 3.1.2 compatibility as ActiveAdmin locks formtastic at 3.1, but I haven't spent much time in the formtastic code.

Quick solution to this for some folks. In your formtastic.rb initializer (for 3.1), you can add the namespace of inputs to find your FormtasticBootstrap inputs like so:

Add this as you normally would:

# You can add custom inputs or override parts of Formtastic by subclassing Formtastic::FormBuilder and
# specifying that class here.  Defaults to Formtastic::FormBuilder.
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder

Update the lines for FormBuilder.input_namespaces and FormBuilder.action_namespaces as follows:

# Define custom namespaces in which to look up your Input classes. Default is
# to look up in the global scope and in Formtastic::Inputs.
Formtastic::FormBuilder.input_namespaces = [ ::Object, ::FormtasticBootstrap::Inputs, ::Formtastic::Inputs ]

# Define custom namespaces in which to look up your Action classes. Default is
# to look up in the global scope and in Formtastic::Actions.
Formtastic::FormBuilder.action_namespaces = [ ::Object, ::FormtasticBootstrap::Actions, ::Formtastic::Actions ]

I'm in the midst of upgrading a site to rails 4.1, so this may not be a 100% complete solution. It does fix issues I was seeing with hint and hint_class on inputs though.

@jkelleyj : it seems to be working quiet well except for select_input, apparently because of

  include Base::GroupedCollections

if you remove it, it works well

@jkelleyj Would you be able to provide a PR to adjust this in the gem?

Similar change was done in activeadmin/activeadmin#3633
I do not know if formtastic-bootstrap has own form builder or not. But if yes, it should be trivial to use new namespaces.

Thanks @optimum-dulopin and @mikz. @sodabrew I'll give it a shot today with the @mikz approach.

@sodabrew I'm getting some basic rspec setup issues w/ formtastic when trying to run tests.
This line:
https://github.com/mjbellantoni/formtastic-bootstrap/blob/master/spec/spec_helper.rb

That adds the formtastic spec helper is unhappy because:
<module:FormtasticSpecHelper>': uninitialized constant RSpec::Mocks::Double (NameError)

Am I missing something obvious with the testing setup?

After a bit more fiddling I noted an rspec version difference between formtastic and this repo. Going to try bumping to 2.14 (from 2.12.2) as part of this PR

@sodabrew I saw in the readme that lots of tests aren't passing. Can you give me a sense of how many were failing before so I can tell if anything broke with my upgrade to 2.14?

Resolving these issues in #116

Merged #116.