Skip to content

Instantly share code, notes, and snippets.

@nowk
Last active December 19, 2015 02:09
Show Gist options
  • Save nowk/5881460 to your computer and use it in GitHub Desktop.
Save nowk/5881460 to your computer and use it in GitHub Desktop.
Angular.js directive for inline form errors when using Formtastic
angular.module("app", [])
.directive 'formtasticInlineErrors', ($compile) ->
return {
restrict: 'A'
link: (scope, element, attrs) ->
scope.$on 'event:form-FormErrors', (evt, model_name, errors) ->
element.find('.input .inline-error').remove()
if !errors? || errors.length == 0
else
$.each errors, (k, err, i) ->
error_html = '<p class="inline-error">'+err.join(", ")+"</p>"
element.find('#'+model_name+'_'+k+'_input').append error_html
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment