Formtastic causes div class="fieldWithErrors" to not appear when using form_for #132

Closed
pupeno opened this Issue Nov 22, 2009 · 15 comments

Comments

Projects
None yet
3 participants

pupeno commented Nov 22, 2009

In a Rails project where I am including the Formtastic gem I have the following non-Formtastic form:

<% form_for(@weight) do |f| %>
<%= f.error_messages %>
<%= f.label :weight %>:
<%= f.text_field :weight, :size => 5 %> kg.
<%= f.submit "Add weight" %>
<%= f.error_message_on :weight %>
<% end %>

which renders to

Weight:
kg.

but when I cause a validation error (weight is required) I don't get the proper div class="fieldWithErrors" wrapper. I get this:

1 error prohibited this weight from being saved

There were problems with the following fields:

  • Weight can't be blank

Weight:
kg.

can't be blank

Just for reference I should have gotten this:

1 error prohibited this weight from being saved

There were problems with the following fields:

  • Weight can't be blank
Weight
:
kg.
can't be blank

If I use semantic_form_for I get the same behavior.

I originally asked about this on Stack Overflow where you can find some more details: http://stackoverflow.com/questions/747220/rails-validation-and-fieldwitherrors-wrapping-select-tags

Contributor

grimen commented Nov 22, 2009

What Formtastic gem version you use?

pupeno commented Nov 22, 2009

I'm running justinfrench-formtastic (0.2.4)

Contributor

grimen commented Nov 22, 2009

I'm like 95% sure this works if you just update to current gem version. I saw you asked about this back in April at Stackoverflow, and at that time Formtastic didn't respect this. I patched this myself, so I'm aware of this used to be a problem.

pupeno commented Nov 22, 2009

grimen, I'm running the latest one installed by gem install today. Should I get an even more recent one? How?

BTW, on April I wasn't doing any Rails, so it must have been someone else.

Contributor

grimen commented Nov 22, 2009

The patch was included in 0.2.5+ version of the gem. I think you should upgrade either way; FOrmtastic is under heavy development and there been plenty of bug fixes since 0.2.4 - should not break anything.

Contributor

grimen commented Nov 22, 2009

Closing.

pupeno commented Nov 22, 2009

grimen, can you confirm the bug is present in the current release but not in the development branch?

Contributor

grimen commented Nov 22, 2009

It's in 0.2.5+, I'm 100% sure. But I still suggest 0.9.2.

pupeno commented Nov 22, 2009

Oh, the reason I was picking an old one is because I was using justinfrench-formtastic instead of formtastic from gemcutter.

Owner

justinfrench commented Nov 22, 2009

Pupeno, the gem is now on Gemcutter, so you'll need to add that as a source. If you're still having trouble, please have a chat on the google group.

pupeno commented Nov 22, 2009

I had gemcutter on my sources but I was installing justinfrench-formtastic instead of formtastic.

Thanks.

pupeno commented Nov 22, 2009

Ok, with formtastic 0.9.2 it's working fine as long as I use form_for. If I use semantic_form_for and use the form_for methods inside, I get the broken behavior (not sure if this is something you'd consider a bug or just the current behavior).

Contributor

grimen commented Nov 22, 2009

It's the expected behavior for Formtastic - but it's not interfering with form_for.

Owner

justinfrench commented Dec 1, 2009

pupeno, instead of the div wrapper that Rails uses (which can cause all sorts of CSS positioning issues and limitations, we remove that wrapper and add an "error" class to the wrapper around the input, which is better because it means you can actually style the whole li block, or the label, or anything else associated with the error.

This issue was closed.

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