Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Oct 3, 2016
1 parent 8399826 commit dda849d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 41 deletions.
44 changes: 19 additions & 25 deletions dist/angular-validator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-validator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 12 additions & 15 deletions src/provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@ angular.module 'validator.provider', []

errorMessage = if error.constructor is String then error else ''
(value, scope, element, attrs) ->
parent = $(element).parent()
until parent.length is 0
if parent.hasClass 'form-group'
parent.addClass 'has-error'
for label in parent.find('label') when $(label).hasClass 'error'
$(label).remove()
$label = $ "<label class='control-label error'>#{errorMessage}</label>"
$label.attr('for', attrs.id) if attrs.id
if $(element).parent().hasClass 'input-group'
$(element).parent().parent().append $label
else
$(element).parent().append $label
break
parent = parent.parent()
parent = element.closest '.form-group'
if parent.length
parent.addClass 'has-error'
for label in parent.find('label') when $(label).hasClass 'error'
$(label).remove()
$label = $ "<label class='control-label error'>#{errorMessage}</label>"
$label.attr('for', attrs.id) if attrs.id
if element.parent().hasClass 'input-group'
element.parent().parent().append $label
else
element.parent().append $label

@convertSuccess = (success) ->
###
Expand All @@ -62,7 +59,7 @@ angular.module 'validator.provider', []
return success if typeof success is 'function'

(value, scope, element) ->
parent = $(element).parent()
parent = element.parent()
until parent.length is 0
if parent.hasClass 'has-error'
parent.removeClass 'has-error'
Expand Down

0 comments on commit dda849d

Please sign in to comment.