mercredi 21 août 2019

Nested Forms in Angular 5

I'm trying to create components which may have nested forms. I'm nesting them because I'd like validation at multiple stages, even though I'll save only once. Maybe there's another solution to my problem, but right now my code looks a bit like this:

<form (submit)="save()" #form1="ngForm">
    <form (submit)="accept()" #form2="ngForm">
        <!-- #form2 fields -->
        <button id="submit2" type="submit" />
    </form>
    <!-- #form1 fields -->
    <button id="submit1" type="submit" />
</form>

When I click #submit2 button, it submits my #form1 form, which I did not expect. How could this be solved?




Aucun commentaire:

Enregistrer un commentaire