如何仅在提交时验证表单,并以角度显示警报表单中的错误消息
How to validate form only on submit and show error messages in alert form in angular?
我想创建一个表单,只在用户单击提交按钮时检查验证,而且错误也应该像引导程序类型的弹出窗口或警报一样出现,我对angular非常陌生,我不知道如何实现这一点。
这是我的表格
<div class="main-container version-msg-wrapp loginpage-bg">
<div class="login-inner-container">
<div class="logo-cont"></div>
<div class="inputs-container">
<form name="userLogin" novalidate>
<div class="input-element-row">
<div class="rgt-input-box fl"><span class="center-icon action-icon"></span><input type="text" ng-model="Nuser.centerCode" placeholder="Center Code" name="centerCode" value="" ng-maxlength="5" required/></div>
<div class="cb">
</div>
<div class="input-element-row">
<div class="rgt-input-box fl"><span class="user-icon action-icon"></span><input type="text" placeholder="User ID" ng-model="Nuser.userID" name="userID" value="" ng-maxlength="20" required/></div>
<div class="cb"></div>
</div>
<div class="input-element-row">
<div class="rgt-input-box fl"><span class="pswd-icon action-icon"></span><input type="password" placeholder="Password" ng-model="busyUser.password" name="password" value="" required /></div>
<div class="cb"></div>
</div>
<div class="input-element-row">
<button type="button" name="" value="" ng-click="StudentSubmit()">Login</button>
</div>
<div ng-show="submitted && userLogin.centerCode.$dirty && userLogin.$invalid" class="alert alert-danger">
<div ng-show="userLogin.centerCode.$error.required">
Center code is required.
</div>
<div ng-show="userLogin.centerCode.$error.maxLength">
Enter Max 5 characters only
</div>
</div>
<div ng-show=" submitted && userLogin.userID.$dirty && userLogin.userID.$invalid " class="alert alert-danger">
<div ng-show="userLogin.userID.$error.required">
User Id is required.
</div>
<div ng-show="userLogin.centerCode.$error.maxLength">
Enter Max 20 characters only
</div>
</div>
<div ng-show="submitted && userLogin.password.$dirty && userLogin.password.$invalid" class="alert alert-danger">
<div ng-show="userLogin.password.$error.required">
enter password
</div>
</div>
</form>
<div class="input-element-row">
<div class="forgot-pass"><a href="#/forgotPassword">Forgot password?</a></div>
</div>
</div>
</div>
我曾经尝试过这样的方法,在点击提交按钮并创建一个提交的变量并在studentSubmit函数中将其设置为true后,将验证显示到表单中的div中,现在我希望这些消息显示在屏幕上的警告框中,让我了解如何使用
<div ng-show="submitted && userLogin.centerCode.$dirty && userLogin.$invalid" class="alert alert-danger">
<div ng-show="userLogin.centerCode.$error.required">
Center code is required.
</div>
<div ng-show="userLogin.centerCode.$error.maxLength">
Enter Max 5 characters only
</div>
</div>
<div ng-show=" submitted && userLogin.userID.$dirty && userLogin.userID.$invalid " class="alert alert-danger">
<div ng-show="userLogin.userID.$error.required">
User Id is required.
</div>
<div ng-show="userLogin.centerCode.$error.maxLength">
Enter Max 20 characters only
</div>
</div>
<div ng-show="submitted && userLogin.password.$dirty && userLogin.password.$invalid" class="alert alert-danger">
<div ng-show="userLogin.password.$error.required">
enter password
</div>
</div>
相关文章:
- 如何创建一个“;表单弹出框“;在chrome中右键单击时位于突出显示的单词上方
- jQuery动态表单显示在select选项上
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 将表单张贴到MailChimp,但显示动态成功页面
- HTML5在提交并显示所需标签后显示隐藏的表单元素
- HTML多页表单显示隐藏部分,保留表单数据
- 使用JavaScript将数据从一个表单显示到另一个页面
- Php 搜索表单显示结果时无需按搜索按钮,而它应该等到按下按钮才能显示它们
- HTML:如何使一个表单显示在另一个表单之上
- 值通过表单提交,然后即使在提交并显示值之后,也会以表单显示已提交的值
- 提交时的 Jquery 表单显示成功消息
- 是否有可接受的跨平台方法在基于触摸的设备上以标准 Web 表单显示数字键盘
- 如何将表单显示从=更改为:
- 表单显示问题+数组下的结果
- 自动完成使用Alpaca表单显示密钥和值
- Google appscript表单显示供用户选择的数组值
- 引导提交表单显示从javascript计时器
- 表单显示PHP HTML
- 基于PHP ajax的表单显示空白页面
- ASP.NET表单显示另一个字段中基于节的表单字段