Dynamic Rails error help
- Tags
- Posted
- Mon 22 Sep, 2008
- Comments
- 2
Here’s a little JavaScript snippet I just wrote for our apps. It parses the standard error messages Rails displays then puts dynamic popup error messages on each of the corresponding form inputs. This allows people to quickly see the error on each field. It currently only displays one error per field, but that could easily be fixed.
You can customise it a bit with by passing a list of options:
initialize: function(objectName, options) {
this.options = {
errorTextSelector: '#errorExplanation ul li',
messageClass: 'popinfo_inner'
}
Be aware that the error popup I’m using uses some existing CSS/layout that our apps already use, so you’ll want to customise showError.
Usage:
Instantiate the ModelErrors class with the name of your model:
new ModelErrors('issue')
Download here: model_error.js

David
Oct 6
I like the look / position of the popup, can you share the CSS that was used to do that?
alex
Oct 6
Cheers David. The CSS is similar to what I wrote for Tiktrac's "popinfo" items. If you search through the CSS for popinfo you'll see it:
https://helicoid.tiktrac.com/stylesheets/screen.css
I had to adapt it a little bit so it could change width, I think the original CSS is fixed.