Skip nested forms validation with AngularJS

后端 未结 12 2044
失恋的感觉
失恋的感觉 2020-12-23 18:16

How can I skip validation of nested forms with AngularJS? I have to make an outer form valid even when its child form is invalid.

In the example below outer form sh

12条回答
  •  失恋的感觉
    2020-12-23 18:26

    In Angular forms can be nested. This means that the outer form is valid when all of the child forms are valid as well.

    So there is no way to make outer form to be valid automatically (through $valid key) when one of inner invalid.

    Try to use error.required

       

    Outer form (valid={{!fOuter.txtOuter.$error.required}})

    Demo Fiddle

    From Angular ngForm docs:

    The other way should be to use controller, like:

    Outer form (valid={{isOuterFormValid}})

    controller

    $scope.isOuterFormValid = true;
    
    // here, add listener on each input and change flag `isOuterFormValid`
    ... 
    

提交回复
热议问题