Set form as invalid in angularjs
angularjs
Solution
After some research the following code works fine for me. In the controller:
//Set the form as invalid for start.
$timeout(function(){
$scope.orderForm.productsForm.$invalid = true;
});
The timeout assures that we gain access to the form. They are not constructed on the first pass through controller so a timeout or watch is needed. Then we mark form as invalid. A better way could be locating an input that we can mark as invalid using documented api `$setValidity` on ngModelController, but in my use case there is no input yet so we do it in a dirty way.
One caveat is that when one sets this directly like above the corresponding $invalid === ! $valid invariant is broken, so be careful with this hack.
Problem
I need to set ng-form as invalid in the start, as it is a later part of a wizard. The form contains a grid with elements. Each element has its own validation, but the issue is that when there are no elements the form shows as valid. I need to mark it as invalid for the start case when the number of rows is 0. How can one do it?