我有一个angularjs表单,它从范围中提取默认数据。使用默认数据,表格将被验证,因此启用按钮进行提交,但反之亦然,除了在输入字段中输入数据,这将启用按钮。这是片段
<div ng-controller="FormValidationController as frmValidationController" class="ui basic segment">
<form class="ui form" name="frmValidation" novalidate>
<div ng-class = "{'has-error':frmValidation.option1.$invalid && !frmValidation.option1.$pristine}"
class="required field">
<label>Selection</label>
<input ng-model="option" ng-minlength="3" formcontrol
name="option1" placeholder="Option" type="text"
class="ng-dirty ng-valid ng-touched" required>
<div _ngcontent-c5="" ngxerrors="option1">
<div class="input-error-message" ngxerror="validName" hidden="">
selection should be there
</div>
</div>
<p ng-show = "frmValidation.option1.$invalid && !frmValidation.option1.$pristine"
class = "input-error-message">required</p>
</div>
如果模型有数据,那么按钮应该在启动时启用,但这种情况永远不会发生,我希望它发生
<button ng-click="submit(); frmValidationController.submitForm(frmValidation.$valid)"
ng-disabled ="!frmValidation.$dirty || frmValidation.$invalid"
class="ui primary button" tabindex="0" type="submit">
Proceed
</button>
答案 0 :(得分:1)
问题在于:
ng-disabled ="!frmValidation.$dirty || frmValidation.$invalid"
具体做法是:
!frmValidation.$dirty
如果实际用户与其进行了互动,则表单只是脏的。由于您正在加载默认数据,因此表单已正确填写,但用户未触及或“污染”#34;它
删除该检查,它应该按预期工作我相信。