我试图在表单验证中显示错误。但这些信息始终可见。
<form name="user-form" method="POST" action="{{route('registrationUser')}}">
<div class="col-lg-8">
Логин <input type="text" name="log" ng-model="mobile" required pattern="[a-zA-Z ]*"><br>
<span class="help-block" ng-show="errors.log[0]"><p>Только английский</p></span>
</div>
Пароль <input type="text" name="pass" ng-minlength="8" ng-pattern="regex" required pattern="[a-zA-Z]{8,32}" ><br>
<div ng-show="user-form.pass.$error.pattern">Name doesn't match pattern!</div>
<button ng-click='SaveUser()' name="Регистрация">Регисрация</button>
</form>
你可以向ng-show添加另一个条件
<div ng-show="user-form.pass.$error.pattern && buttonclicked">Name doesn't match pattern!</div>
并在控制器中将该条件设置为 true
$scope.SaveUser= function () {
$scope.buttonclicked = true;
};
因此,只有当用户单击"提交"按钮时,错误消息才会可见