angular-validator icon indicating copy to clipboard operation
angular-validator copied to clipboard

requiredSubmit is not working with ng-include

Open rubydoc opened this issue 11 years ago • 4 comments

In controller, I declare this.

$scope.user = 
    username: ''
    password: ''
    submit: () ->
      $validator.validate $scope, 'user'
      .success () ->
        Auth.signUp
          username: $scope.user.username
          password: $scope.user.password
        .then  ()->
          $location.path "/helloworld"
      .error ->
        console.log "err"

In view

 <form name="form" novalidate>
    <div ng-include="'/partials/auth/sign-up-form'">
    </div>
    <button ng-click="user.submit()" class="btn btn-lg btn-success">Sign Up</button>
</form>

/partials/auth/sign-up-form.html

<div class="input-group form-group"> 
  <span class="input-group-addon form-title">
    <label for="username">username</label>
  </span>
  <input type="text" class="form-control" id="username" ng-model="user.username" placeholder="username" validator="[required, requiredSubmit]">
</div>

When I use without ng-include, well done. I have checked the user is same scope wheather using ng-include or not. I can't understand what is defferent. How to can I fix it?

rubydoc avatar Jul 22 '14 02:07 rubydoc

Hello @victorkim I think the $scope in ng-include and the $scope at container are different.

$validator.validate $scope, 'user'

You should replace $scope as one in ng-include.

kelp404 avatar Jul 22 '14 07:07 kelp404

Another solution is to use a controller in the form. Controllers are better suited for this casses, than $scope itself.

genuinefafa avatar Jul 22 '14 12:07 genuinefafa

Thanks for answer.

I checked angular-validator code.

The ng-include update value parent scope through user prototype. But validator event binded in ng-include's scope and triggered by container's scope.

So @kelp404 and @genuinefafa solution is should working. But I don't want making meaningless controller.

If I make some form with modal(http://angular-ui.github.io/bootstrap/), controller scope different with scope. Modal controller have only form logic. But I just add a controller for validator. This is bad for my project.

I want to find better solution.(Because I love this project and I want keep this lib in my project.)

rubydoc avatar Jul 23 '14 02:07 rubydoc

@victorkim I understand where you are going, and I agree with you. Maybe it's time to improve the validator if no other solution is found. ;)

genuinefafa avatar Jul 23 '14 13:07 genuinefafa