Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

field_error_proc override breaks standard form_for error handling #39

Closed
jonbuda opened this Issue Aug 25, 2009 · 18 comments

Comments

Projects
None yet
6 participants

jonbuda commented Aug 25, 2009

For most forms I've been using formtastic, however a few forms I don't need all the features so I'm sticking to good old form_for(@object). I've noticed that when the Formtastic gem is enabled (latest version 0.2.1), form_for no longer wraps input elements in a fieldWithErrors tag if validation has failed. Commenting out the config.gem entry and everything is back to normal.

Contributor

grimen commented Sep 2, 2009

By the look on this it seems to be quite hard to solve. Maybe that's a cost one has to pay to get a better form builder - very cheap if u ask me, I never run into such issue in one year of usage. Supporting this in 0.9 feels like wrong priority - especially if there's no obvious solution?

Owner

justinfrench commented Sep 6, 2009

This might seem like it's been over-prioritized, but it's very important to me (and absolutely part of the whole plugin's design) that Formtastic doesn't change the default behavior of Rails built in form helpers and form behavior, because Formtastic doesn't suit every situation and every form.

So if possible, I'd really like this resolved. I think José had some ideas. If it's impossible, we'll revisit.

Owner

justinfrench commented Sep 30, 2009

awesome! your commit isn't very atomic (gemspec, etc) so I'll have to grab all the bits by hand, but this is very awesome, thanks!

jonbuda commented Sep 30, 2009

rock! thanks!

Contributor

grimen commented Sep 30, 2009

Yes, I forgot to mention - the gemspec in master is invalid since the last commits. You should re-generate it. Also, if not adding it, pkg dir should be in .gitignore.

Owner

justinfrench commented Sep 30, 2009

grimen, any chance you can rebuild your fork to be nice and clean with a rebase or whatever? I'm happy to pick it apart or copy-paste if you're busy, let me know either way.

Contributor

grimen commented Sep 30, 2009

Yes, I should be ashamed - so looking into it now. (After I finished peeping the new Rails 3 update talk - awesome!) ;)

Contributor

grimen commented Oct 1, 2009

Done. I sent a new pull-request.

Contributor

grimen commented Oct 1, 2009

And yea, don't forget to update the gemspec - I ignored to commit that this time. It references no longer existing files.

Owner

justinfrench commented Oct 3, 2009

pulled in, with thanks... will create separate issue for the gemspec.

Contributor

tokland commented Oct 20, 2012

I am confused, apparently this issue was solved long ago but inspecting the code we see that field_error_proc is still being unconditionally modified behind the programmer's back (https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/helpers/form_helper.rb). Any hints?

Owner

justinfrench commented Oct 25, 2012

@tokland which specific lines of code are you referencing? Might be worth opening a new issue?

Contributor

tokland commented Oct 25, 2012

This method overrides field_error_proc inconditionally inside a semantic_form_for:

def with_custom_field_error_proc(&block)
  default_field_error_proc = ::ActionView::Base.field_error_proc
  ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
  yield
ensure
  ::ActionView::Base.field_error_proc = default_field_error_proc
end

Now I realize it's not the same situation, the OP was using form_for (that's indeed solved now) while I'd like to have the option to keep the old field_error_proc even within a semantic_form_for. So it's related but no exactly the same.

Owner

justinfrench commented Oct 31, 2012

@tokland right, so you're asking for the field error proc to be configurable inside Formtastic? Seems like something we can do, please create a new issue to ensure this gets tracked properly, but I think something like this in an initializer might work:

Formtastic::Helpers::FormHelper::FIELD_ERROR_PROC = ::ActionView::Base.field_error_proc

Or something custom:

Formtastic::Helpers::FormHelper::FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
  # whatever you want
end

This didn't work for me

Formtastic::Helpers::FormHelper::FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
  # whatever you want
end

This did

field_error_proc = proc do |html_tag, instance_tag|
   # whatever you want
end

Formtastic::Helpers::FormHelper.class_variable_set(:@@field_error_proc, field_error_proc) 

I guess because of this commit

bughit commented Sep 24, 2013

ActionView::Base.field_error_proc is being overridden by by including Formtastic via ActiveAdmin
Rails 4.0.0, Formtasctic 2.3.0rc2

@justinfrench justinfrench reopened this Sep 24, 2013

Owner

justinfrench commented Apr 18, 2014

I believe the original issue has been resolved in #899. Please re-open if I've missed something. If there's related issues, I'd prefer new, clean issues to track.

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