@@ -1549,22 +1549,170 @@ describe('input', function() {
1549
1549
expect ( scope . name ) . toEqual ( 'caitp' ) ;
1550
1550
} ) ;
1551
1551
1552
- it ( 'should not dirty the model on an input event in response to a placeholder change' , inject ( function ( $sniffer ) {
1553
- if ( msie && $sniffer . hasEvent ( 'input' ) ) {
1554
- compileInput ( '<input type="text" ng-model="name" name="name" />' ) ;
1555
- inputElm . attr ( 'placeholder' , 'Test' ) ;
1556
- browserTrigger ( inputElm , 'input' ) ;
1557
-
1552
+ describe ( "IE placeholder input events" , function ( ) {
1553
+ //IE fires an input event whenever a placeholder visually changes, essentially treating it as a value
1554
+ //Events:
1555
+ // placeholder attribute change: *input*
1556
+ // focus (which visually removes the placeholder value): focusin focus *input*
1557
+ // blur (which visually creates the placeholder value): focusout *input* blur
1558
+ //However none of these occur if the placeholder is not visible at the time of the event.
1559
+ //These tests try simulate various scenerios which do/do-not fire the extra input event
1560
+
1561
+ it ( 'should not dirty the model on an input event in response to a placeholder change' , function ( ) {
1562
+ compileInput ( '<input type="text" placeholder="Test" attr-capture ng-model="unsetValue" name="name" />' ) ;
1563
+ msie && browserTrigger ( inputElm , 'input' ) ;
1558
1564
expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1559
1565
expect ( inputElm ) . toBePristine ( ) ;
1560
1566
1561
- inputElm . attr ( 'placeholder' , 'Test Again' ) ;
1562
- browserTrigger ( inputElm , 'input' ) ;
1567
+ attrs . $set ( 'placeholder' , '' ) ;
1568
+ msie && browserTrigger ( inputElm , 'input' ) ;
1569
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( '' ) ;
1570
+ expect ( inputElm ) . toBePristine ( ) ;
1563
1571
1572
+ attrs . $set ( 'placeholder' , 'Test Again' ) ;
1573
+ msie && browserTrigger ( inputElm , 'input' ) ;
1564
1574
expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test Again' ) ;
1565
1575
expect ( inputElm ) . toBePristine ( ) ;
1566
- }
1567
- } ) ) ;
1576
+
1577
+ attrs . $set ( 'placeholder' , undefined ) ;
1578
+ msie && browserTrigger ( inputElm , 'input' ) ;
1579
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( undefined ) ;
1580
+ expect ( inputElm ) . toBePristine ( ) ;
1581
+
1582
+ changeInputValueTo ( 'foo' ) ;
1583
+ expect ( inputElm ) . toBeDirty ( ) ;
1584
+ } ) ;
1585
+
1586
+ it ( 'should not dirty the model on an input event in response to a interpolated placeholder change' , inject ( function ( $rootScope ) {
1587
+ compileInput ( '<input type="text" placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1588
+ msie && browserTrigger ( inputElm , 'input' ) ;
1589
+ expect ( inputElm ) . toBePristine ( ) ;
1590
+
1591
+ $rootScope . ph = 1 ;
1592
+ $rootScope . $digest ( ) ;
1593
+ msie && browserTrigger ( inputElm , 'input' ) ;
1594
+ expect ( inputElm ) . toBePristine ( ) ;
1595
+
1596
+ $rootScope . ph = "" ;
1597
+ $rootScope . $digest ( ) ;
1598
+ msie && browserTrigger ( inputElm , 'input' ) ;
1599
+ expect ( inputElm ) . toBePristine ( ) ;
1600
+
1601
+ changeInputValueTo ( 'foo' ) ;
1602
+ expect ( inputElm ) . toBeDirty ( ) ;
1603
+ } ) ) ;
1604
+
1605
+ it ( 'should dirty the model on an input event while in focus even if the placeholder changes' , inject ( function ( $rootScope ) {
1606
+ $rootScope . ph = 'Test' ;
1607
+ compileInput ( '<input type="text" ng-attr-placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1608
+ expect ( inputElm ) . toBePristine ( ) ;
1609
+
1610
+ browserTrigger ( inputElm , 'focusin' ) ;
1611
+ browserTrigger ( inputElm , 'focus' ) ;
1612
+ msie && browserTrigger ( inputElm , 'input' ) ;
1613
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1614
+ expect ( inputElm ) . toBePristine ( ) ;
1615
+
1616
+ $rootScope . ph = 'Test Again' ;
1617
+ $rootScope . $digest ( ) ;
1618
+ expect ( inputElm ) . toBePristine ( ) ;
1619
+
1620
+ changeInputValueTo ( 'foo' ) ;
1621
+ expect ( inputElm ) . toBeDirty ( ) ;
1622
+ } ) ) ;
1623
+
1624
+ it ( 'should not dirty the model on an input event in response to a ng-attr-placeholder change' , inject ( function ( $rootScope ) {
1625
+ compileInput ( '<input type="text" ng-attr-placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1626
+ expect ( inputElm ) . toBePristine ( ) ;
1627
+
1628
+ $rootScope . ph = 1 ;
1629
+ $rootScope . $digest ( ) ;
1630
+ msie && browserTrigger ( inputElm , 'input' ) ;
1631
+ expect ( inputElm ) . toBePristine ( ) ;
1632
+
1633
+ $rootScope . ph = "" ;
1634
+ $rootScope . $digest ( ) ;
1635
+ msie && browserTrigger ( inputElm , 'input' ) ;
1636
+ expect ( inputElm ) . toBePristine ( ) ;
1637
+
1638
+ changeInputValueTo ( 'foo' ) ;
1639
+ expect ( inputElm ) . toBeDirty ( ) ;
1640
+ } ) ) ;
1641
+
1642
+ it ( 'should not dirty the model on an input event in response to a focus' , inject ( function ( $sniffer ) {
1643
+ compileInput ( '<input type="text" placeholder="Test" ng-model="unsetValue" name="name" />' ) ;
1644
+ msie && browserTrigger ( inputElm , 'input' ) ;
1645
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1646
+ expect ( inputElm ) . toBePristine ( ) ;
1647
+
1648
+ browserTrigger ( inputElm , 'focusin' ) ;
1649
+ browserTrigger ( inputElm , 'focus' ) ;
1650
+ msie && browserTrigger ( inputElm , 'input' ) ;
1651
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1652
+ expect ( inputElm ) . toBePristine ( ) ;
1653
+
1654
+ changeInputValueTo ( 'foo' ) ;
1655
+ expect ( inputElm ) . toBeDirty ( ) ;
1656
+ } ) ) ;
1657
+
1658
+ it ( 'should not dirty the model on an input event in response to a blur' , inject ( function ( $sniffer ) {
1659
+ compileInput ( '<input type="text" placeholder="Test" ng-model="unsetValue" name="name" />' ) ;
1660
+ msie && browserTrigger ( inputElm , 'input' ) ;
1661
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1662
+ expect ( inputElm ) . toBePristine ( ) ;
1663
+
1664
+ browserTrigger ( inputElm , 'focusin' ) ;
1665
+ browserTrigger ( inputElm , 'focus' ) ;
1666
+ msie && browserTrigger ( inputElm , 'input' ) ;
1667
+ expect ( inputElm ) . toBePristine ( ) ;
1668
+
1669
+ browserTrigger ( inputElm , 'focusout' ) ;
1670
+ msie && browserTrigger ( inputElm , 'input' ) ;
1671
+ browserTrigger ( inputElm , 'blur' ) ;
1672
+ expect ( inputElm ) . toBePristine ( ) ;
1673
+
1674
+ changeInputValueTo ( 'foo' ) ;
1675
+ expect ( inputElm ) . toBeDirty ( ) ;
1676
+ } ) ) ;
1677
+
1678
+ it ( 'should dirty the model on an input event if there is a placeholder and value' , inject ( function ( $rootScope ) {
1679
+ $rootScope . name = 'foo' ;
1680
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1681
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1682
+ expect ( inputElm ) . toBePristine ( ) ;
1683
+
1684
+ changeInputValueTo ( 'bar' ) ;
1685
+ expect ( inputElm ) . toBeDirty ( ) ;
1686
+ } ) ) ;
1687
+
1688
+ it ( 'should dirty the model on an input event if there is a placeholder and value after focusing' , inject ( function ( $rootScope ) {
1689
+ $rootScope . name = 'foo' ;
1690
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1691
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1692
+ expect ( inputElm ) . toBePristine ( ) ;
1693
+
1694
+ browserTrigger ( inputElm , 'focusin' ) ;
1695
+ browserTrigger ( inputElm , 'focus' ) ;
1696
+ changeInputValueTo ( 'bar' ) ;
1697
+ expect ( inputElm ) . toBeDirty ( ) ;
1698
+ } ) ) ;
1699
+
1700
+ it ( 'should dirty the model on an input event if there is a placeholder and value after bluring' , inject ( function ( $rootScope ) {
1701
+ $rootScope . name = 'foo' ;
1702
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1703
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1704
+ expect ( inputElm ) . toBePristine ( ) ;
1705
+
1706
+ browserTrigger ( inputElm , 'focusin' ) ;
1707
+ browserTrigger ( inputElm , 'focus' ) ;
1708
+ expect ( inputElm ) . toBePristine ( ) ;
1709
+
1710
+ browserTrigger ( inputElm , 'focusout' ) ;
1711
+ browserTrigger ( inputElm , 'blur' ) ;
1712
+ changeInputValueTo ( 'bar' ) ;
1713
+ expect ( inputElm ) . toBeDirty ( ) ;
1714
+ } ) ) ;
1715
+ } ) ;
1568
1716
1569
1717
1570
1718
it ( 'should interpolate input names' , function ( ) {
0 commit comments