validations = []
isEmpty = (string) ->
string is '' or string is undefined or string == null
createValidation = (scopeVariable, expected, responseText, inverse) ->
if inverse == undefined
inverse = false
if !inverse
returningValidation = ->
if scopeVariable isnt expected
$scope.response.text = responseText
$scope.response.class = 'text-danger'
return false
true
else
returningValidation = ->
if scopeVariable is expected
$scope.response.text = responseText
$scope.response.class = 'text-danger'
return false
true
returningValidation
validateCredentials = ->
validated = true
validations.map (validate) ->
if !validate()
validated = false
validated
$scope.register = ->
if validateCredentials()
#Account.register $scope.form, (response) ->
#if response.user_created is true
$scope.response.text = '...'
$scope.response.class = 'text-success'
validations.push createValidation $scope.form.termsChecked, true, '...'
validations.push createValidation $scope.form.password, $scope.form.passwordRepeat, '...'
inverse = true
validations.push createValidation $scope.form.password, undefined, '...', inverse
validations.push createValidation $scope.form.password, '', '...', inverse
I have an AngularJS app with a form validation that I'm triying to create. There's a function being created to each kind of validation. It is supposed to be passed the $scope.form.input
object to each input. But it looks like it's getting passed by value. I really don't know how it works in this kind of JS closure.
Any kind of information would be helpfull.