How to manually trigger a form's submit in AngularJS?

前端 未结 5 1032
感动是毒
感动是毒 2020-12-30 02:34

I have a form that I wanted be nested, but it is not possible since HTML can\'t accept nested form. Is there a way I can manually invoke the submit(triggers the validation,

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 03:07

    I've answered a similar question here AngularJS - How to trigger submit in a nested form

    Basically, you can trigger validation by firing $validate event

    isFormValid = function($scope, ngForm) {
        $scope.$broadcast('$validate');
        if(! ngForm.$invalid) {
          return true;
    }
    

    For working code example & a small utility method which is helpful in showing validation messages, see answer in the above link.

提交回复
热议问题