Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular.js ng-form subform validation error in parent form

Tags:

angularjs

I have a form.

<form class="form-horizontal" name="canForm" ng-submit="stepSubmit()" novalidate>

It is called "canForm" as above.

Within this form.. I need a subform for a repeating block of requirements.

I define this form

<div ng-form="licencesForm">

within the "canForm" above.

When I submit the licencesForm for my repeating block I make sure that I set form.$setPristine() in the controller.

However, when I submit the main canForm, this form picks up on the required fields in my subform and says the main form is invalid.

I cannot understand this. The ng-form directive should be an isolated scope and the parent form should not pick up on the validation requirements of the fields in this subform right?

If the subform is valid, the main form should also be valid shouldn't it?


See http://plnkr.co/edit/gkbJNAV95MQ9SGLeMvlg?p=preview

When you add something in the subform it sets the form to $setPristine() and the subform is valid but clicking submit the main form says the form is not valid even though the subform is valid?

like image 754
markstewie Avatar asked Mar 22 '23 06:03

markstewie


1 Answers

if there is a parent form and sub form then parent form will be valid only when all subforms are valid..

    <form class="form-horizontal" name="canForm" ng-submit="stepSubmit()" novalidate>

and there is a subform

    <div ng-form="licencesForm">

then canForm will be valid only when all licencesForm will be valid.

like image 158
Nitu Bansal Avatar answered Apr 01 '23 15:04

Nitu Bansal