Skip to content

Commit 85934e5

Browse files
committed
Merge branch 'custom_trigger'
2 parents 490a001 + dcfd3a7 commit 85934e5

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/showErrors.coffee

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ showErrorsModule = angular.module('ui.bootstrap.showErrors', [])
22

33
showErrorsModule.directive 'showErrors',
44
['$timeout', 'showErrorsConfig', ($timeout, showErrorsConfig) ->
5-
5+
6+
getTrigger = (options) ->
7+
trigger = showErrorsConfig.trigger
8+
if options && options.trigger?
9+
trigger = options.trigger
10+
trigger
11+
612
getShowSuccess = (options) ->
713
showSuccess = showErrorsConfig.showSuccess
814
if options && options.showSuccess?
@@ -13,14 +19,15 @@ showErrorsModule.directive 'showErrors',
1319
blurred = false
1420
options = scope.$eval attrs.showErrors
1521
showSuccess = getShowSuccess options
22+
trigger = getTrigger options
1623

1724
inputEl = el[0].querySelector '.form-control[name]'
1825
inputNgEl = angular.element inputEl
1926
inputName = inputNgEl.attr 'name'
2027
unless inputName
2128
throw "show-errors element has no child input elements with a 'name' attribute and a 'form-control' class"
2229

23-
inputNgEl.bind 'blur', ->
30+
inputNgEl.bind trigger, ->
2431
blurred = true
2532
toggleClasses formCtrl[inputName].$invalid
2633

@@ -58,11 +65,16 @@ showErrorsModule.directive 'showErrors',
5865

5966
showErrorsModule.provider 'showErrorsConfig', ->
6067
_showSuccess = false
68+
_trigger = 'blur'
6169

6270
@showSuccess = (showSuccess) ->
6371
_showSuccess = showSuccess
72+
73+
@trigger = (trigger) ->
74+
_trigger = trigger
6475

6576
@$get = ->
6677
showSuccess: _showSuccess
78+
trigger: _trigger
6779

6880
return

0 commit comments

Comments
 (0)