Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

IE10 fires input event when a placeholder is defined so that form element is in dirty instead of pristine state #2615

Closed
jupiterplanet opened this issue May 9, 2013 · 8 comments

Comments

@jupiterplanet
Copy link

Input elements in AngularJS can be in pristine state meaning that the input element's value hasn't been modified yet by the user. In this case error messages can be hidden although validation fails because the input field is empty.

AngularJS uses different measures to determine if the value in an input element has changed. It listens to the input event for all browsers supporting this event with the exception of IE9 as this browser does not implement this event correctly.

However, as it turns out IE10 also has implementations faults. If a placeholder is defined on an input element IE10 fires this event when the placeholder is set during DOM loading and when it is removed when the user clicks into the input field so that error messages which depend on the pristine condition are displayed although the user has not yet modified the input's value.

Open the following plunk with IE10 to see this behavior:
http://plnkr.co/LqlkhtIPPEwgP0znR7vz

Click into the e-mail input field and the error message displays although the input's value has not changed yet.

In all other browsers (Chrome, IE9, Firefox) the error message is not displayed.

A workaround is to not use the input event just like for IE9.

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;
        }]);
    }]).
@jupiterplanet
Copy link
Author

Seems that this issue made it two times into the issue list. Sorry. I close it as I cannot see any way to delete it.

@ghost
Copy link

ghost commented Feb 18, 2014

I am still getting this issue on IE 10

@caitp
Copy link
Contributor

caitp commented Feb 18, 2014

@jkevinburton, unfortunately we can't stop MSIE from emitting input events at weird times :( There is a fix to prevent this from causing ngModel inputs to be dirtied, but it hasn't been merged yet. See #5960

@grimwinoleader
Copy link

This is definitely annoying. Well, anything with IE/Microsoft generally is :' ) @caitp, thanks for the reference to #5960

@travischoma
Copy link

Also have this issue in IE 10.

@davsket
Copy link

davsket commented May 21, 2014

I have this issue in IE11

@primavera133
Copy link

I also have this issue in IE10

@tdakhla
Copy link

tdakhla commented May 30, 2014

In case anyone isn't using 1.3.0-beta.6+, there's a bug in the above $provide.decorator code - it should be return _hasEvent.call(this, event); instead of just _hasEvent.call(this, event);.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants