Skip to content

Commit

Permalink
added a promises then. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Apr 1, 2014
1 parent 325dede commit 870f2bc
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 81 deletions.
21 changes: 18 additions & 3 deletions dist/angular-validator.js

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

28 changes: 14 additions & 14 deletions dist/angular-validator.min.js

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

34 changes: 18 additions & 16 deletions example/demo.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

a = angular.module 'app', ['validator', 'validator.rules']
angular.module 'app', ['validator', 'validator.rules']

# ----------------------------------------
# config
# ----------------------------------------
a.config ($validatorProvider) ->
.config ($validatorProvider) ->
# backendWatch
$validatorProvider.register 'backendWatch',
invoke: 'watch'
validator: (value, scope, element, attrs, $injector) ->
$http = $injector.get '$http'
h = $http.get 'example/data.json'
h.then (response) ->
$http.get 'example/data.json'
.then (response) ->
if response and response.data
not (value in (x.name for x in response.data))
else
Expand All @@ -21,8 +21,8 @@ a.config ($validatorProvider) ->
$validatorProvider.register 'backendSubmit',
validator: (value, scope, element, attrs, $injector) ->
$http = $injector.get '$http'
h = $http.get 'example/data.json'
h.then (response) ->
$http.get 'example/data.json'
.then (response) ->
if response and response.data
not (value in (x.name for x in response.data))
else
Expand All @@ -33,8 +33,8 @@ a.config ($validatorProvider) ->
invoke: 'blur'
validator: (value, scope, element, attrs, $injector) ->
$http = $injector.get '$http'
h = $http.get 'example/data.json'
h.then (response) ->
$http.get 'example/data.json'
.then (response) ->
if response and response.data
not (value in (x.name for x in response.data))
else
Expand Down Expand Up @@ -66,7 +66,7 @@ a.config ($validatorProvider) ->
# ----------------------------------------
# run
# ----------------------------------------
a.run ($validator) ->
.run ($validator) ->
$validator.register 'requiredRun',
invoke: 'watch'
validator: /^.+$/
Expand All @@ -76,7 +76,7 @@ a.run ($validator) ->
# ----------------------------------------
# controller
# ----------------------------------------
a.controller 'DemoController', ($scope, $validator) ->
.controller 'DemoController', ($scope, $validator) ->
$scope.formWatch =
required: ''
regexp: ''
Expand All @@ -92,13 +92,15 @@ a.controller 'DemoController', ($scope, $validator) ->
http: ''
# the submit function
submit: ->
v = $validator.validate $scope, 'formSubmit'
v.success ->
$validator.validate $scope, 'formSubmit'
.success ->
# validated success
console.log 'success'
v.error ->
.error ->
# validated error
console.log 'error'
.then ->
console.log 'then'
reset: ->
$validator.reset $scope, 'formSubmit'

Expand All @@ -116,8 +118,8 @@ a.controller 'DemoController', ($scope, $validator) ->
value: ''
]
submit: ->
v = $validator.validate $scope, 'formRepeat'
v.success -> console.log 'success'
v.error -> console.log 'error'
$validator.validate $scope, 'formRepeat'
.success -> console.log 'success'
.error -> console.log 'error'
reset: ->
$validator.reset $scope, 'formRepeat'
Loading

0 comments on commit 870f2bc

Please sign in to comment.