R
R
Robert2016-08-16 16:19:34
JavaScript
Robert, 2016-08-16 16:19:34

How to check the validity of all forms on a page using angular?

There are several forms on the page that are created with ng-repeat and ng-form.
Within the scope of ng-repeat, checking the validity of the form is not a problem.
But how to check the validity of all these forms OUTSIDE of ng-repeat?
The situation is such that the user can dynamically add objects to the array, each object is a new form, in fact.
By clicking on the "Submit" button, there should be no invalid data. But how to make it inactive if at least one form is invalid?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-08-17
@Jowan

PSEUDOCODE:

<div id="form-container">
    <form ng-repeat="f in forms">
        <input ng-model="f.title">
    </form>
</div>
<input type="button" ng-click="submitForms('#form-container')">

function controller(){
    var self = this;
    self.submitForms = function(selector){
        let formContainer = angular.element(selector);
        let forms = formContainer.find('form');
        // и проверяйте валидность форм
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question