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中删除

并在$ digest将更改传播到表单的父节点之一后注入一个新表单。当jQuery插件第一次运行时,它将处理程序附加到 节点;但是这些输入被删除并替换为新的输入,因此按键/更改/提交事件不会触发jQuery处理程序。

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,检查其值并提供反馈。

更多相关文章

  1. 无法在JQuery中查找表单输入
  2. 用于转换单位的HTML和JavaScript表单
  3. jQuery表单验证Validata
  4. Javascript实现统一的表单验证
  5. 【JavaScript】案例一:使用JS完成注册页面表单校验
  6. 如何检查不包含提交按钮的HTML5表单的有效性?
  7. 使用特定顺序的ID列表从Django数据库中获取记录
  8. Django -表单无效但没有错误
  9. 如何在/account / url模式之外使用Django-AllAuth注册表单?

随机推荐

  1. android 开发常用网站
  2. Android Application 之 allowBackup 属
  3. Android之获取Android唯一ID
  4. Android 8.0 权限警告(not in privapp-per
  5. android web
  6. Android:Loader
  7. android toolchain is using Thread mode
  8. android邮件发送几种方式
  9. Android 禁用 APP 或四大组件
  10. Android:Android.bat批处理命令