从验证在angularjs卸下最后NG-形式 [英] Removing last ng-form from validation in angularjs

查看:108
本文介绍了从验证在angularjs卸下最后NG-形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在angularjs一个主从表单。形式是典型的交易,如姓名一些主数据形式,类型等细节部分包含许多行(可以添加和删除)。每一行都有为信用卡,借记卡和账户号码输入字段。我已经能够增加既对形式的掌握部分和细节部分以及使用 NG-形式指令所要求的验证。我的表看起来像以下结果

I have a master detail form in angularjs. The form is typical transactions form with some master data like Name, type etc. The detail part contains many lines (can be added and deleted). Each line has input fields for Credit, Debit and Account Number. I have been able to add the required validations both on master portion of the form and detailed portion as well using ng-form directive. My form looks like following

你可以看到,我已经有添加行按钮,将在细节部分增加一行。现在我有奇怪的要求,即是自动添加一行时,用户最后一排的输入数据。我甚至做了,使用 NG-焦指令而是要求下一部分是从验证上下文中删除最后一行,如果不使用它(不脏),并成功提交剩下的形式。我怎样才能做到这一点的角度。请找到 code对Plunkr 并引导我如何可以删除细节部分的最后一排,从验证情况下,如果它是不脏。

you can see that I already have Add Row button that will add row on detail portion. Now I have strange requirement that is to add a row automatically when user is entering data in last row. I have even done that using ng-focus directive but the next part of requirement is to remove the last row from validation context if it is not used (not dirty) and successfully submit the remaining form. How can I do it in angular. Please find the Code on Plunkr and guide me how I can remove last row of detailed portion from validation context if it is not dirty.

推荐答案

ngRepeat $最后为true最后一行。所以,你可以只禁用 NG-要求如果输入的是最后一行。

ngRepeat sets $last to true for the last row. So you can just disable ng-require if an input is on the last row.

您可以做类似数据-NG-所需=entry.DebitAmoun&安培;!&安培; $!最后一个。并为每个输入类似

You could do something like data-ng-required="!entry.DebitAmoun && !$last" and similar for each input.

如果您认为最后一行总是包含空输入字段以上会工作。每当用户在最后一行添加任何值,则新行创建。

The above will work if you assume that last row always contains empty input fields. Whenever the user adds any value on the last row, then a new row is created.

这篇关于从验证在angularjs卸下最后NG-形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆