Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Error message display
# Introduction
Error messages are currently not handled in a consistent manner in Batchdeux's forms. I have modified the `field_error_proc` method which serves as a global way to change the behavior of form errors. By modifying this, I have given us the option to display errors in several ways:
# Options
Options can be passed on an individual `:input` basis.
* `suppress_error` - Do not show any inline errors
* `error_before` - Show the label tag before the :input tag
* `error_after` - Show the label tag after the :input tag
We can expand these options in the future if needed.
# Implementation
`config/initializers/client_side_validations.rb` contains an override for `ActionView::Base.field_error_proc`
This method uses `Nokogiri` to parse the HTML tag and look at the CSS `class` attribute's value. Specifically it is looking for one of the options above to determine how to render the error.
The html_tag and the label containing the error are both children of a div.field_with_errors element. This has been styled to display a border of 1px solid red on the :input being rendered.
# Deprecation
* Formtastic (semantic_form_for) will no longer be used going forward. Forms that use semantic_form_for do not call field_error_proc, which is our global error display setting. Formtastic errors are hard-coded to use a certain style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.