0

Is it possible to access $dirty property of some element which is not put directly in form, something like:

<form name="form">
    <div name="divInForm">
        <input type="text" name="inputInDivInForm">
    </div>
    <button ng-disabled="form.divInForm.inputInDivInForm.$dirty"></button>
</form>
2
  • 1
    Using "form.inputInDivInForm.$dirty" will do it. Commented Aug 14, 2016 at 21:11
  • inputInDivInForm is inside ng-repeat maybe that's a problem Commented Aug 14, 2016 at 21:37

1 Answer 1

1

At first, you must set ngModel to your input, otherwise it won't work.

Also, you have to access it this way: form.inputInDivInForm.$dirty.

Look at this simple example:

<!DOCTYPE html>
<html ng-app>

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>

<body>
  <form name="form">
    <div name="divInForm">
      <input type="text" ng-model="any" name="inputInDivInForm">
    </div>        
    <button type="submit" ng-disabled="form.inputInDivInForm.$dirty">Click</button>
  </form>
  <pre ng-bind="form.inputInDivInForm | json"></pre>
</body>

</html>

Sign up to request clarification or add additional context in comments.

1 Comment

I have ng-model showing data from a controller, but still does not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.