Last active
December 19, 2015 02:09
-
-
Save nowk/5881460 to your computer and use it in GitHub Desktop.
Angular.js directive for inline form errors when using Formtastic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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