Fix forms.scrollToFirstError when there is no error to scroll to

This commit is contained in:
Scott Erickson 2016-03-09 14:40:07 -08:00
parent 2e96a387e9
commit 46afe40637

View file

@ -84,7 +84,8 @@ module.exports.setErrorToProperty = setErrorToProperty = (el, property, message,
module.exports.scrollToFirstError = ($el=$('body')) ->
$first = $el.find('.has-error, .alert-danger, .error-help-block, .has-warning, .alert-warning, .warning-help-block').filter(':visible').first()
$('html, body').animate({ scrollTop: $first.offset().top - 20 }, 300)
if $first.length
$('html, body').animate({ scrollTop: $first.offset().top - 20 }, 300)
module.exports.clearFormAlerts = (el) ->
$('.has-error', el).removeClass('has-error')