Skip nested forms validation with AngularJS

后端 未结 12 1996
失恋的感觉
失恋的感觉 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:35

    I had the same issue and resolve it with bit change in local copy of angular.js file itself.

    Basically, I added new function to the FormController as below:

    form.$resetParent = function() {
        parentForm = nullFormCtrl;
    };
    

    and create custom directive:

    angular.module('myApp').directive('dtIsolatedForm', function () {
        return {
            restrict: 'A',
            require: '?form',
            link: function (scope, element, attrs, formController) {
                if (!formController || !formController.$parentForm) {
                    return;
                }
    
                formController.$resetParent();
            }
        };
    });
    

提交回复
热议问题