2015-08-25 44 views
6

我想在表单内发送表单,但是当我在表单中提交表单时,现在所有表单都已提交。 它甚至可以做到这一点?里面的表单提交表单?

<form name="add_foobar_form" novalidate ng-submit="addFoobar(foobar)"> 

    <form name="send_contact_form" novalidate ng-submit="sendContact(hello)"> 
     <input type="text" ng-model="hello.bye"> 
     <input type="submit" value="sendmall"> 
    </form> 

    <input type="text" ng-model="foobar.go"> 
    <input type="submit" value="sendall"> 

</form> 
+0

这是内部形状http://stackoverflow.com/questions/379610/can-you-nest-html-forms最好不要嵌套表格 可以尝试提交按钮的形式标签http://www.w3schools.com/tags/att_button_form.asp – Grievoushead

回答

13

Can you have nested forms?只是不,嵌套表单不起作用。

Docs Says

在角,形式可以嵌套。这意味着当所有子表单都有效时,外部表单是 有效。但是,浏览器 不允许嵌套元素,因此Angular提供的嵌套ngform指令的行为相同,但可以是 。这可以让你有嵌套形式,是动态使用ngRepeat指令

产生 但不幸的是,你不能使用ng-submit表格形式采用了棱角分明的验证指令时,这是非常有用的 ,将调用父点击任何内部形式的方法ng-submit

Example Plunkr

的解决方法,这将是不使用ng-submit指令的内部嵌套的。您应该在按钮上使用ng-click并将按钮类型从submit更改为button

标记

<form name="add_foobar_form" novalidate ng-submit="addFoobar('foobar')"> 
    <ng-form name="send_contact_form" novalidate> 
     <input type="text" ng-model="hello.bye"> 
     <input type="button" value="sendmall" ng-click="sendContact('hello')"> 
    </ng-form> 

    <input type="text" ng-model="foobar.go"> 
    <input type="submit" value="sendall"> 
</form> 

Workaround Plunkr

+0

问题是,这两种情况下,相同的事件处理程序被称为 – dfsq

+0

指出..感谢..我的工作.. .. –