AngularJS: list all form errors

前端 未结 4 728
执念已碎
执念已碎 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:50

    I made a function that you pass the form to. If there are form errors it will display them in the console. It shows the objects so you can take a look. I put this in my save function.

    function formErrors(form){
      var errors = [];
      for(var key in form.$error){
        errors.push(key + "=" + form.$error);
      }
      if(errors.length > 0){
        console.log("Form Has Errors");
        console.log(form.$error);
      }
    };
    

提交回复
热议问题