<form name="someForm"> <div class="row">
<div class="col-md-offset-4 col-md-2">
<ul class="list-unstyled">
<li><label for="initials" class="control-label">Initials</label>
</li>
<li>
<div class="input-group">
<input type="text" name="initials"
ng-model="searchDetails.initials"
class="form-control" placeholder="Initials" required />
</div>
</li>
<li><label for="surname" class="control-label">Surname</label>
</li>
<div class="input-group">
<input type="text" name="surname"
ng-model="searchDetails.surname"
class="form-control" placeholder="Surname" required />
</div>
</li>
</ul>
</div>
<div class="col-md-2">
<ul class="list-unstyled">
<li><label>Date of Birth</label></li>
<li>
<div class="input-group">
<input type="text" name="dateOfBirth"
ng-model="searchDetails.dateOfBirth"
class="form-control" placeholder="yyyy-dd-mm" required />
</li>
<li><label>Identity number</label></li>
<li><input type="text" name="identityNumber"
ng-model="searchDetails.identityNumber" class="form-control" placeholder="Identity number" required /> <span
class="form_error" id="idNumberMsg2"
data-ng-show="formName.invalid && formName.identityNumber.$error.invalidId">ID
number does not appear to be authentic.</span></li>
</ul>
</div>
</div>
<span data-ng-show="!(searchDetails.initials && searchDetails.surname && searchDetails.dateOfBirth) || !searchDetails.identityNumber">
Please search by id only or by initials, surname and dateOfBirth
</span>
<div class="row">
<input type="button" tabindex="3" id="searchClient"
class="button_style" value="Next" >
</div>
</form>
我想对提交进行有条件检查,当输入以下三个(姓名缩写,姓氏和dateOfBirth)并且未输入id号时,表单应该没有错误消息,并且当它上面有id号时#39;自己输入,其他三个没有输入,表格也应该通过,否则显示消息错误。任何光线都非常受欢迎。对不起,我是Angular的新手。
答案 0 :(得分:0)
要显示错误消息,请查看ng-messages和ng-message指令。 将其添加到表单元素:
novalidate ng-submit="someForm.$valid && someSubmitMethod()">
使用这样的ng-messages(它正在查看输入字段的name属性,因此输入name =&#34; id&#34;在下面检查:
<ng-messages for="someForm.id.$error" role="alert">
<ng-message when="required">ID is mandatory</ng-message>
</ng-messages>