Yii 2.0.10 防止多次点击和 ActiveForm 提交 [英] Prevent multiple clicks and ActiveForm submission in Yii 2.0.10

查看:18
本文介绍了Yii 2.0.10 防止多次点击和 ActiveForm 提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用 ActiveForms 并且发现它很方便它包括客户端验证脚本 yii.jsyii.activeForm.js.它通常会自行处理模型规则和基本验证.

I use ActiveForms often and find it handy as it includes client-side validation scripts yii.js and yii.activeForm.js. It normally takes care of model rules and basic validation on its own.

直到 Yii 2.0.9:
我们可以使用以下脚本来防止由于快速按钮点击而导致多个表单提交:

Until Yii 2.0.9:
We could use following script to prevent multiple form submission due to rapid button clicks:

$('form').submit(function(){
    $(this).find('button[type!="button"],input[type="submit"]').attr("disabled",true);
    setTimeout(function(){
        $('form .has-error').each(function(index, element) {
            $(this).parents("form:first").find(":submit").removeAttr("disabled");
        });
    },1000);
});

但是,
当前的 Yii 2.0.10 版本带来了一些变化,但上面的脚本失败了.现在,如果上面的代码执行,它不会提交表单.
之前也曾在此处讨论过它,并已被确定为错误.
因为,yii.js 有两个变化:

But,
Current Yii 2.0.10 release brought some changes and fails above script. Now, it will not submit the form if above code executes.
It has also been discussed earlier here and has been identified as bug.
Since, yii.js had two changes:

  1. 错误 #10358:修复了 yii.js AJAX 预过滤器 (silverfire) 中的竞争条件
  2. Enh #12580:使 yii.js 遵守严格和非严格的 javascript 模式,以允许与外部代码 (mikehaertl) 连接

而且,yii.activeForm.js 有四个变化:

  1. 错误 #10681:在 yii.activeForm.js (silverfire) 中恢复了 beforeValidate 事件调用的修复
  2. Enh #12376:向 yii.activeForm.js validate() 方法添加参数以能够强制验证 (DrDeath72)
  3. Enh #12499:当启用 AJAX 验证时,yii.activeForm.js 将在表单提交时强制运行它以显示所有可能的错误(silverfire)
  4. Enh #12744:将 afterInit 事件添加到 yii.activeForm.js (werew01f)

可以用 v2.0.9 的 oder js 文件替换吗?

替换js文件是否会导致崩溃和意外行为?

是否有更好的解决方案来防止多次提交?

推荐答案

问题好像已经解决了.
那些通过 composer 安装了新版 Yii 2.0.10 的不会出现这个问题;而那些从从存档文件安装"部分下载存档文件的人可能仍会遇到此问题,因为他们可能没有更新存档文件.

It looks like the issue had been taken care of, already.
Those who have installed fresh Yii 2.0.10 via composer will not have this issue; while, those who downloaded an archived file from 'Install from an Archive File' section may still have this issue since they might not have updated the archive files.

如果您遇到这个特定问题,那么您所要做的就是替换 github 源.如果是本地拷贝,这个文件可以位于vendoryiisoftyii2assetsyii.activeForm.js.

If you are facing this specific issue, then all you have to do is replace a specific file framework/assets/yii.activeForm.js from the github source. In case of local copy, this file can be located at vendoryiisoftyii2assetsyii.activeForm.js.

这篇关于Yii 2.0.10 防止多次点击和 ActiveForm 提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆