基于两种不同形式的 ng 禁用按钮
Ng-disabled button based on two different forms
在处理项目时,我遇到了一个问题,只要 2 个不同的表(行中有一个 ng-repeat,这反过来又有每行所需的输入)仍然有空字段,我需要禁用一个按钮。所以基本上:
<table class="table table-striped fontsize12">
<thead>
<tr>
<th class="width-desc-auto">Description</th>
<th class="width-reg-auto">Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td><h6>{{item.DESCRIPTION}}</h6></td>
<td>
<input type="text" class="form-control" ng-model="item.VALUE"
placeholder="{{item.VALUE}}" disabled="true" required
>
</td>
</tr>
</tbody>
和:
<table class="table table-striped fontsize12">
<thead>
<tr>
<th class="width-desc-auto">Description</th>
<th class="width-reg-auto">Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="char in chars">
<td><h6>{{char.DESCRIPTION}}</h6></td>
<td>
<input type="text" class="form-control"
ng-model="char.VALUE" placeholder="Register Value" required
>
</td>
</tr>
</tbody>
第一个是自动填写的,但在某些情况下它们仍然是空的,第二个必须手动输入。我重复的实际数组并不重要。现在,我通过在两个表周围放置一个表单标签来解决它,并将按钮也包含在该表单标签中。
<form name="myForm">
<table>...</table>
<table>...</table>
<span class="pull-right">
<button class="btn btn-sm btn-primary" type="button" ng-disabled="myForm.$invalid">
Close
</button>
</span>
</form>
这有效,但是如果我需要将两个表都放在不同的形式中怎么办?例如自动表单和手动表单?我是否需要将实际按钮也放在表单标签中?因为如果我把它放在它外面,它似乎不起作用。
如果之前有人问过这个问题,我很抱歉,但我找不到它。提前泰。
只要表在同一范围内,您实际上就不需要表单标签。 您只需检查ng禁用指令中两个输入字段的值并相应地禁用它例如,在这里您可以使用
<button class="btn btn-sm btn-primary" type="button"
ng-disabled="!(item.value && char.value)"
>
Close
</button>
在这种情况下,按钮仅在两种输入类型都填充时启用
相关文章:
- ng disabled在chrome中不起作用.按钮在角度上未禁用
- 角度无线电按钮ng模型不起作用
- 当我的所有 Ng-from 都有效时启用一个按钮
- Ng点击记住单选按钮选择
- 使用ng-hide根据条件显示/隐藏按钮
- 如果ng单击附加到提交按钮,则表单未验证
- 为什么ng-click被称为按钮被点击的次数
- 将 ng 重复中的单选按钮设置为选中
- 在 Angular JS 中重新启用禁用 ng 的按钮
- 嵌套ng中的Angularjs单选按钮重复未选中
- 如何在控制器内获取ng重复单选按钮值
- 使用嵌套ng中带有单选按钮的ng模型重复不起作用
- 在Angular中绑定剑道网格按钮's ng click
- 按下按钮时,ng点击不起作用
- ng单击mdListItem和辅助按钮
- 使用AngularJS处理嵌套ng重复.无法通过ng单击来获取按钮
- 禁用fieldset ng不适用于angular js中的按钮
- 角度ng内的多个单选按钮组重复
- Safari中Angular ng显示的按钮闪烁
- ng按钮错误不工作,只显示一条消息angularjs