当名称字段点和支架采用了棱角分明验证表单 [英] Validating form using Angular when name field has dots and brackets

查看:181
本文介绍了当名称字段点和支架采用了棱角分明验证表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要验证的形式是主从,即它有两个部分。主部分包含两个字段,而细节部分最初有两行,但他们可以在pssing DOM的按钮来增加$ P $。该表格​​看起来像以下

The form to be validated is master detail i.e. it has two portions. master portion contains two fields while detail portion initially has two rows but they can be increased by pressing a button on DOM. The form looks like the following

问题是,在细节部分我用来创建输入 NG-重复

The problem is that in detail portion I have to create the inputs using ng-repeat like

<div class="form-group">
          <table style="margin-left:10%;">
             <tr>
                <th>Account id</th>
                <th>Amount</th>

             </tr>
             <tr class="edit-row" ng-repeat ="entry in model.Entries">
                <td>

                   <input type="text" ng-model="model.Entries[$index].AccountId" required  name="Entries[{{$index}}].AccountId"/>


                </td>
                <td>
                   <input type="text" ng-model="model.Entries[$index].Amount" required name="Entries[{{$index}}].Amount"/> 
                   <span class="field-validation-error text-danger" ng-show="transactionForm['Entries['{{$index}}'].Amount'].$invalid && transactionForm['Entries['{{$index}}'].Amount'].$dirty">
                     Amount is Required
                   </span>
                </td>


             </tr>

          </table>

       </div>

NG-节目属性没有对细节部分做工精细。这是因为,我有圆点(。)和在输入字段的名称括号([)。我怎么能在这样的情况下执行验证。有人可能会争辩改变输入的名字,但我不得不使用这种约定输入名称中的细节部分。在目前的code,我用括号标记金额场的 NG-节目属性为<一个描述href=\"http://stackoverflow.com/questions/19403239/how-to-validate-the-form-using-angularjs-when-the-name-field-has-dot-in-it\">This SO质疑,但无济于事。你可以在 plunker

But the ng-show attribute is not working fine for the detail portion. This is because, I have dots (.) and brackets ([) in the name of input fields. How can I perform validation in such scenario. Someone may argue to change the names of the input but I have to use this convention for input names in the detail portion. In current code, I have used bracket notation in ng-show attribute of Amount field as described in This SO question, but to no avail. you can find complete example at plunker

推荐答案

可以做这样的事?

       ng-show="model.Entries[$index].Amount === ''"

而不是试图检查表单值检查实际模型值。这将工作假设你只是检查,以确保没有比空字符串以外的值。你将不得不使检查更具体的你在找什么。您还可以设置类型=数字,如果你只想让用户输入一个数值。

Rather than trying to check the form value check the actual model value. This will work assuming you are just checking to make sure there is a value other than the empty string. You will have to make the check more specific to what you are looking for. You can also set the type="number" if you only want to allow the user to enter a numeric value.

这篇关于当名称字段点和支架采用了棱角分明验证表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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