Skip nested forms validation with AngularJS

后端 未结 12 2085
失恋的感觉
失恋的感觉 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 18:18

    From your controller :

    Ctrl.isOuterFormValid = function() {
        var outerFormIsValid = true;
        for(var prop in Ctrl.formName) {
            //The form is only inValid if the property is not a new form and it is invalid
            if(pvCtrl.pvForm[prop].constructor.name !== "FormController" &&
               pvCtrl.pvForm[prop].$invalid){
                outerFormIsValid = false;
            }
        }
    
        alert(outerFormIsValid);
    };
    

    FormController is an Object that gives you information about your form state.
    Adding a form to a form, with ng-form is adding a FormController property to your original FormController Object.

    This has the advantage of not adding a html directive to all your input elements.

提交回复
热议问题