【发布时间】:2015-03-21 19:24:11
【问题描述】:
在一个表单 (itemSelectionForm) 中,我使用 ng-repeat 呈现多个表。在每个表中,我都有单选按钮,其名称后附有索引。现在,我想编写一个 Angular JS 指令(selectAtleastOneItemToReturn),我将把它放在表单上(使用 select-atleast-one-item),它将基于子表单选按钮进行表单验证。现在,我不知道如何在该指令中访问这些子表单选按钮及其值,以便编写验证代码。而且,如果单选按钮的值发生变化,我想一次又一次地进行验证。如果表单无效,则下一步按钮将被禁用。 HTML如下。
<div class="panel-group" data-ng-form="itemSelectionForm" select-atleast-one-item>
<div class="panel panel-default" data-ng-repeat="item in items">
<div class="panel">
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Action</th>
<th>Item Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
<input type="radio" name="inputRadios{{$index}}" value="option 1" data-ng-model="item.action" required/>
</label>
</td>
<td>{{item.description}}</td>
</tr>
<tr>
<td>
<label>
<input type="radio" name="inputRadios{{$index}}" value="option 2" data-ng-model="item.action" required/>
</label>
</td>
<td colspan="2">Option 2</td>
</tr>
<tr>
<td>
<label>
<input type="radio" name="inputRadios{{$index}}" value="option 3" data-ng-model="item.action" required/>
</label>
</td>
<td colspan="2">Option 3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="right">
<button type="submit" class="btn green-button left space-left" data-ng-disabled="itemSelectionForm.$invalid" data-ng-click="goForward()">Next</button>
</div>
【问题讨论】:
标签: javascript html angularjs