AngularJS: list all form errors

前端 未结 4 726
执念已碎
执念已碎 2021-01-29 23:45

Background: I am currently working on an application with tabs; and I\'d like to list the fields / sections that fail validation, to direct the user to look for errors in the r

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 23:56

    If you have nested forms then you will find this helpful:

     function touchErrorFields(form) {
        angular.forEach(form.$error, function (field) {
          angular.forEach(field, function(errorField) {
            if (!errorField.hasOwnProperty('$setTouched')) {
              touchErrorFields(errorField);
            } else {
              errorField.$setTouched();
            }
          })
        });
      }
    

提交回复
热议问题