formtastic-bootstrap icon indicating copy to clipboard operation
formtastic-bootstrap copied to clipboard

as: :select unrecognized input on non-model form when using PostgreSQL

Open sam0x17 opened this issue 10 years ago • 11 comments

EDIT: turns out it had nothing with moving to postgresql --- I ran bundle update and that pushed formtastic to 3.0.0, which is what broke everything. See https://github.com/mjbellantoni/formtastic-bootstrap/issues/109#issuecomment-56828388 for solution

I had a form that was working perfectly when I was using SQLite. I moved to PostgreSQL and for some reason this broke formtastic-bootstrap's ability to recognize :select as an input type.

Formtastic::UnknownInputError - "Unable to find input class for select"

To reproduce this error try the following:

$ rails new select-error-app --database=postgresql
$ rails g scaffold Post title:string body:text
$ rake db:create
$ rake db:migrate
$ rake db:setup

Add the following to the top of the auto-generated app/views/posts/index.html.erb file:

<%= semantic_form_for 'filter_form' do |f| %>
  <%= f.input :test, as: :select, collection: {"item 1" => 1, "Item 2" => 2, "Item 3" => 3} %>
  <%= f.actions %>
<% end %>

Add the required styles and gem files etc for formtastic-bootstrap

Now run rails server

$ rake rails server

Navigate to http://localhost:3000 in your web browser. You should now get the same error I'm getting.

This is a model-less form, which is supported according to the formtastic documentation as long as you specify an "as:" for each input.

As far as I can tell this will not throw the same error if you use SQLite.

What could be causing this error?

sam0x17 avatar Sep 24 '14 19:09 sam0x17

What versions of rails, formtastic, formtastic-bootstrap are you using?

sodabrew avatar Sep 24 '14 20:09 sodabrew

Using bootstrap-sass 3.2.0.2
Using formtastic 3.0.0
Using formtastic-bootstrap 3.0.0
Using rails 4.1.5

sam0x17 avatar Sep 24 '14 20:09 sam0x17

formtastic-bootstrap 3.0 actually only support formtastic 2.x. Try downgrading to formtastic 2.3.1 and see if it resolves the issue?

sodabrew avatar Sep 24 '14 20:09 sodabrew

That worked, though it made all the bootstrap styles on my form elements stop working :/

sam0x17 avatar Sep 24 '14 20:09 sam0x17

Yeah it looks like once I did that none of my text inputs are using the new bootstrap styles. Is there a way to fix this and still use the bootstrap 3.x styles?

sam0x17 avatar Sep 24 '14 21:09 sam0x17

UPDATE: so it looks like I have to force formtastic-bootstrap to be 3.0.0, but keep formtastic at 2.3.1 and then everything works.

sam0x17 avatar Sep 25 '14 14:09 sam0x17

Yes, that's the expected combination. I will update the gemspec today to show the f-b 3 doesn't support f 3.

sodabrew avatar Sep 25 '14 16:09 sodabrew

Are there any plans to support formtastic 3? ActiveAdmin has moved into requiring formtastic 3, so there will be no way to use latest activeadmin and formtastic-bootstrap...

glampr avatar Sep 28 '14 22:09 glampr

I'm happy to accept Pull Requests to make us compatible with Formtastic 3. I'm not sufficiently familiar with the changes in F3 to know if we can be compatible with both Formtastic 2.3 and 3.0 at the same time – mostly this is a matter of picking sensible version numbers.

sodabrew avatar Sep 29 '14 01:09 sodabrew

UPDATE: this is fixed with this commit: https://github.com/mjbellantoni/formtastic-bootstrap/commit/18fab411ee597a1543b4499b4c69d65e019c1fdd

Formtastic is still v 3.0.0 as my gem previously stated, but sourcing from github brings that important commit which fixes this situation.

hakunin avatar Dec 08 '14 10:12 hakunin

Thanks for the update. I'll try to make time for a release soon.

sodabrew avatar Dec 08 '14 21:12 sodabrew