AngularJS /如何防止IE触发自动输入验证? [英] AngularJS / How to prevent IE triggering automatically inputs validation?

查看:191
本文介绍了AngularJS /如何防止IE触发自动输入验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些形式的页面。

每个表单都包含一些字段限制,比如 required 等等。



我只想在验证时显示错误,只有当用户与它们交互时(UX?=>是)。

事实上,只要字段是 $ pristine 意思是没有触及,不应该显示错误。



我设法用很多浏览器来达到这个要求,除了.. 。 Internet Explorer (尤其是IE> 10)。
事实上,IE似乎从一开始就将所有字段视为 $ dirty



浏览web,我发现这个修复:
$ b $ pre $ my code MyMainAppModule.config(['$ provide',function($ provide){
$ provide.decorator('$ sniffer',['$ delegate',function($ sniffer){
var msie = parseInt((/ msie(\ d +)/ .exec(angular.lowercase( navigator.userAgent))|| [])[1],10);
var _hasEvent = $ sniffer.hasEvent;
$ sniffer.hasEvent = function(event){
if(event ==='input'&& msie> 10){
return false;
}
_hasEvent.call(this,event);
};
return $ sniffer;
}]);

运行它并... wowww IE现在玩得很好
然后在Safari Mobile(Iphone)中运行...失望
为什么?因为任何输入的字符都在将AFTER事件处理程序(如 $ watch 等)考虑在内,从而导致所期望的与所发生的事情之间的转换。
之前在Safari Mobile中运行良好,这真是遗憾。因此,实际的困境是:优先考虑Safari Mobile或IE:)

有人曾经在IE中试验过这种情况?
是否还有其他可以实现的更好的修复?

解决方案

返回 _hasEvent.call(this,event);

I have some page with some forms.
Each form contains some constraints on fields, like required and more.

I want to display errors on validation only when user interacts with them (UX? => yes).
Indeed, as long as the field is $pristine meaning no touched, no errors should be displayed.

I managed to achieve this requirement with a lot of browsers, except... Internet Explorer (especially IE > 10). Indeed, IE seems to consider all fields as $dirty from the beginning!

Surfing on the web, I found this "fix":

MyMainAppModule.config(['$provide', function ($provide) {
        $provide.decorator('$sniffer', ['$delegate', function ($sniffer) {
            var msie = parseInt((/msie (\d+)/.exec(angular.lowercase(navigator.userAgent)) || [])[1], 10);
            var _hasEvent = $sniffer.hasEvent;
            $sniffer.hasEvent = function (event) {
                if (event === 'input' && msie > 10) {
                    return false;
                }
                _hasEvent.call(this, event);
            };
            return $sniffer;
        }]);

Running it and... wowww IE plays nicely now. Running it then in Safari Mobile (Iphone)...disappointment. Why? Because any typed characters are taking into account AFTER event handlers like $watch etc...leading to a shift between what was expected with what occured. It's a pity since it worked well in Safari Mobile before.

So, the actual dilemma is: to give priority to Safari Mobile or IE :)

Has someone ever experimented this situation in IE? Is there some other "better" fixes that I could implement?

解决方案

RETURN _hasEvent.call(this, event);

这篇关于AngularJS /如何防止IE触发自动输入验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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