4

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

See this plnkr.co/edit/gkbJNAV95MQ9SGLeMvlg?p=preview. I am setting the subform to $setPristine() which sets the licencesForm to valid
@markstewie your plnkr code was really helpful. It would be really nice if you could post the code here itself, as an answer for the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.