Skip to content

requiredSubmit is not working with ng-include #21

Open

Description

@rubydoc

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?

Activity

  1. kelp404 commented on Jul 22, 2014

    @kelp404
    Owner

    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.

  2. genuinefafa commented on Jul 22, 2014

    @genuinefafa

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

  3. rubydoc commented on Jul 23, 2014

    @rubydoc
    Author

    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.)

  4. genuinefafa commented on Jul 23, 2014

    @genuinefafa

    @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. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions