[英]How do I make dynamically created radio buttons required - AngularJs
I have a table with varying amount of rows. 我有一个表,其中行的数量不同。
<table>
<thead>
<tr>
<th class="text-center">Name</th>
<th class="text-center">Select Supervisor</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employeeInfo in employees" class="ng-cloak text-center">
<td>{{employeeInfo.name}} {{employeeInfo.lastname}}</td>
<td>
<label><input type="radio" ng-model="employeeInfo.attributes[0].value" ng-value="true" ng-change="updateEmployeeAttribute(employeeInfo)">Approve</label>
<label><input type="radio" ng-model="employeeInfo.attributes[0].value" ng-value="false" ng-change="updateEmployeeAttribute(employeeInfo)">Reject</label>
</td>
</tr>
</tbody>
</table>
<div>
<a id="Approve" class="btn btn-primary" ng-click="approveSupervisorChanges()">Submit</a>
</div>
One of the columns contain radio buttons "Approve" & "Reject" 列之一包含单选按钮“批准”和“拒绝”
How do I make it a requirement that in all rows the user has to have selected a radio button before he can submit ? 我如何要求用户在所有行中都必须选择一个单选按钮才能提交?
I tried this solution Validate Radio Button AngularJS by adding 我尝试通过添加以下方法来验证单选按钮AngularJS
ng-required="!employeeInfo.attributes[0].value"
But then it seems that accepted is a requirement, and if rejected is selected I can't submit 但是,似乎接受是一个要求,如果选择了拒绝,我将无法提交
you can put required attribute simply like: 您可以像下面这样放置必填属性:
<label><input type="radio" required ng-model="employeeInfo.attributes[0].value" ng-value="true" ng-change="updateEmployeeAttribute(employeeInfo)">Approve</label>
<label><input type="radio" required ng-model="employeeInfo.attributes[0].value" ng-value="false" ng-change="updateEmployeeAttribute(employeeInfo)">Reject</label>
Ok so I got it working using by using ng-required like this. 好的,这样我就可以通过使用ng-required来使用它了。
<label><input type="radio" ng-required="employeeInfo.attributes[0].value" ng-model="employeeInfo.attributes[0].value" ng-value="true" ng-change="updateEmployeeAttribute(employeeInfo)">Approve</label>
<label><input type="radio" ng-required="!employeeInfo.attributes[0].value" ng-model="employeeInfo.attributes[0].value" ng-value="false" ng-change="updateEmployeeAttribute(employeeInfo)">Reject</label>
Which isn't really perfect(but it works) as when noting is selected, a popup highlights only the reject radio button and says "Please select one of these options" 这并不是真正的完美选择(但它可以工作),因为在选择“注意”时,弹出窗口仅突出显示“拒绝”单选按钮并显示“请选择以下选项之一”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.