![](/img/trans.png)
[英]How to invalidate a form in angularjs? (or how to disable a form in angularjs?)
[英]AngularJS:how to disable all the form controls in a form?
我想禁用所有表單組件,以便在單擊視圖按鈕時無法編輯它。 這是我的表格
<form action="#" class="form-horizontal" >
<div class="form-group">
<label for="fieldname" class="col-md-3 control-label">Name</label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected" typeahead="name as name.name for name in members | filter:{name:$viewValue}" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="fieldhname" class="col-md-3 control-label">House name</label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected1" typeahead="house_name as house_name.house_name for house_name in family | filter:{house_name:$viewValue}" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="" class="col-md-3 control-label"><?php echo $this->lang->line('label_family_id'); ?></label>
<div class="col-md-6">
<input type="text" ng-model="newItem.customSelected2" typeahead="fm as fm.family_reg_no for fm in family | filter:{family_reg_no:$viewValue}" class="form-control" />
</div>
</div>
<div class="col-md-3"></div>
</form>
這是我的按鈕
<input type="button" class="finish btn-success btn" ng-click="view(newItem)" value="view"/>
您可以將所有表單元素放入fieldset並使用ng-disabled來禁用整個字段集,而不是在每個字段級別處理它。
您可以使用fieldset
通過與周圍的按鈕標簽fieldset
,並使用ng-disabled
屬性:
<form action="#" class="form-horizontal" >
<fieldset ng-disabled="isClicked">
<!--your form here --!>
</fieldset>
</form>
現在剩下的就是在view(newItem)
函數中執行:
$scope.view = function(newItem){
$scope.isClicked = true;
// Your code here and set it to false when your are done with it
}
您可以使用疊加並在其上顯示ng-show,或者您可以添加到每個輸入ng禁用
ng-disabled
與范圍變量結合使用可禁用字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.