【问题标题】:Angular, getting Ng-required of checked checkbox (or radio) in ng-repeatAngular,在 ng-repeat 中选中复选框(或单选框)需要 Ng
【发布时间】:2015-04-10 09:59:03
【问题描述】:

我想验证一个在 ng-repeat 中带有多个单选复选框的表单。 我应该如何使用单选按钮输入验证所选选项:
ng-repeat 之外的验证工作正常。例如。将 $index 切换到 customDish 时。 问题是在 ng-repeat 中使用 $index 进行验证。

必填字段应准确显示在 ng-repeat 循环内的选定单选按钮上。

这是一个小家伙

[http://plnkr.co/edit/j6bswtctD0ixaQmcDrp1?p=preview][1]

请帮忙
提前致谢

  [1]: http://plnkr.co/edit/j6bswtctD0ixaQmcDrp1?p=preview

【问题讨论】:

  • 能写的更清楚点吗?我不明白你的意思。
  • 从顶部单击提交必填字段中选择三个单选按钮之一显示在所有显示中只显示给所选

标签: javascript angularjs validation indexing angularjs-ng-repeat


【解决方案1】:

另一种解决方案

 <input ng-pattern="onlyNumbers" placeholder="quantity" ng-required="$parent.checkboxSelection === {{$index}}" name="dishQuantity{{$index}}" id="dishPrice" data-ng-model="dish.quantity" type="text" class="dish-quantity" id="dishQuantity" /> 

和跨度标签

<span class="custom-label-danger" ng-show="submitClicked && myOrderForm.dishQuantity{{$index}}.$error.required ">Field Required</span>

也在工作:)

【讨论】:

    【解决方案2】:

    只需将此与您的 ng-show 进行比较:

    ng-show="submitClicked && myOrderForm.dishQuantity.$error.required && 
    ($parent.checkboxSelection == $index)"
    

    我又添加了一个条件,以确保该错误仅针对选定的项目显示。

    【讨论】:

    • 是的,这是一个正确的解决方案,谢谢您的回答:)
    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    相关资源
    最近更新 更多