validate dynamic form before submitting angular


I’m dynamically creating forms with ng-repeat and they have some validation attributes (simplified version):

<div class="row" ng-repeat="defect in model.defects">
    <form name="form_{{}}" novalidate>
      <input ng-model="" required/>
      <input type="submit" ng-click="saveDefect(defect)"/>

Basically what I want to do is this:

$scope.saveDefect = function (defect) {
         if ($scope.<how to get the form name here>.$invalid) {

Since the form name has been created dynamically with an id how do I access it? Other ways of doing the same are also welcome ofcourse 🙂


You can use the bracket notation to access it :


What I advise you to do is :

var app = angular.module("App", []);
app.controller("Ctrl", function($scope) {
  $scope.forms = {};
  $scope.list = [{id: 1}, {id: 2}];
  $ = function(item) {
    if ($scope.forms["form_" +].$invalid) {
      alert("error on form_" +;
<script src=""></script>

<body ng-app="App" ng-controller="Ctrl">
  <div class="row" ng-repeat="item in list">
    <form name="forms.form_{{}}" novalidate>
      <input ng-model="" required/>
      <input type="submit" ng-click="save(item)" />

Answered By – IggY

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.