如何解决Angular appliacation中“消失”的jQuery验证问题?
We have this Angular (1.2.19) page which utlizes the jQuery validation library for form validation. Sometimes all validation functionality disappears: people can just submit whatever they want and nothing is validated. This behaviour occurs perhaps 50% of the time and otherwise works fine. No errors present in the console.
我们有这个Angular(1.2.19)页面,它使用jQuery验证库进行表单验证。有时,所有验证功能都会消失:人们只需提交他们想要的任何内容,就无需验证任何内容。这种行为可能发生在50%的时间,否则工作正常。控制台中没有错误。
Our current theory is that this might have something to do with the order that javascript files are loaded, and that sometimes the are loaded in an order that creates conflict but not sure how to verify this since no errors show up?
我们当前的理论是,这可能与加载javascript文件的顺序有关,有时加载的顺序会产生冲突但不确定如何验证这一点,因为没有错误出现?
Here's our index file script
这是我们的索引文件脚本
<!-- JQUERY -->
<script type="text/javascript" src="libs/userjs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="libs/userjs/jquery-validation/dist/jquery.validate.js"></script>
<script type="text/javascript" src="js/extra-validator-methods.js"></script>
<!-- ANGULAR CORE JS -->
<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-animate/angular-animate.min.js"></script>
<script src="libs/angular-route/angular-route.min.js"></script>
<script type="text/javascript" src="libs/angular-qr/lib/qrcode.js"></script>
<script type="text/javascript" src="libs/angular-qr/angular-qr.min.js"></script>
<script type="text/javascript" src="libs/angular-validate/angular-validate.js"></script>
1 个解决方案
#1
1
The order of the scripts is not the issue; they're loading in the same order every time (they're blocking includes).
脚本的顺序不是问题;他们每次都以相同的顺序加载(他们阻止包括)。
More likely, Angular is removing the <form>
from the DOM and injecting a new one after $digest propagates a change to one of the form's parent nodes. When the jQuery plugin ran the first time, it attached handlers to the <input>
nodes; but those inputs got removed and replaced with new ones, so the keypress/change/submit events aren't triggering the jQuery handlers.
更有可能的是,Angular正在从DOM中删除
It's best to use Angular event handlers (like ng-change
, ng-submit
, etc.) to validate the inputs from within an Angular controller. Trying to manage the state of the form with both Angular and jQuery will be a drag.
最好使用Angular事件处理程序(如ng-change,ng-submit等)来验证Angular控制器中的输入。尝试使用Angular和jQuery来管理表单的状态将是一个拖累。
Use ng-model
to track each field in your controller, and on ng-change
, check their values and provide feedback.
使用ng-model跟踪控制器中的每个字段,以及ng-change,检查其值并提供反馈。
更多相关文章
- 无法在JQuery中查找表单输入
- 用于转换单位的HTML和JavaScript表单
- jQuery表单验证Validata
- Javascript实现统一的表单验证
- 【JavaScript】案例一:使用JS完成注册页面表单校验
- 如何检查不包含提交按钮的HTML5表单的有效性?
- 使用特定顺序的ID列表从Django数据库中获取记录
- Django -表单无效但没有错误
- 如何在/account / url模式之外使用Django-AllAuth注册表单?