@@ -1388,22 +1388,188 @@ describe('input', function() {
1388
1388
expect ( scope . name ) . toEqual ( 'caitp' ) ;
1389
1389
} ) ;
1390
1390
1391
- it ( 'should not dirty the model on an input event in response to a placeholder change' , inject ( function ( $sniffer ) {
1392
- if ( msie && $sniffer . hasEvent ( 'input' ) ) {
1393
- compileInput ( '<input type="text" ng-model="name" name="name" />' ) ;
1394
- inputElm . attr ( 'placeholder' , 'Test' ) ;
1395
- browserTrigger ( inputElm , 'input' ) ;
1391
+ describe ( "IE placeholder input events" , function ( ) {
1392
+ //IE fires an input event whenever a placeholder visually changes, essentially treating it as a value
1393
+ //Events:
1394
+ // placeholder attribute change: *input*
1395
+ // focus (which visually removes the placeholder value): focusin focus *input*
1396
+ // blur (which visually creates the placeholder value): focusout *input* blur
1397
+ //However none of these occur if the placeholder is not visible at the time of the event.
1398
+ //These tests try simulate various scenerios which do/do-not fire the extra input event
1399
+
1400
+ it ( 'should not dirty the model on an input event in response to a placeholder change' , function ( ) {
1401
+ if ( msie ) {
1402
+ compileInput ( '<input type="text" placeholder="Test" attr-capture ng-model="unsetValue" name="name" />' ) ;
1403
+ browserTrigger ( inputElm , 'input' ) ;
1404
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1405
+ expect ( inputElm ) . toBePristine ( ) ;
1406
+
1407
+ attrs . $set ( 'placeholder' , '' ) ;
1408
+ browserTrigger ( inputElm , 'input' ) ;
1409
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( '' ) ;
1410
+ expect ( inputElm ) . toBePristine ( ) ;
1411
+
1412
+ attrs . $set ( 'placeholder' , 'Test Again' ) ;
1413
+ browserTrigger ( inputElm , 'input' ) ;
1414
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test Again' ) ;
1415
+ expect ( inputElm ) . toBePristine ( ) ;
1416
+
1417
+ attrs . $set ( 'placeholder' , undefined ) ;
1418
+ browserTrigger ( inputElm , 'input' ) ;
1419
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( undefined ) ;
1420
+ expect ( inputElm ) . toBePristine ( ) ;
1421
+
1422
+ changeInputValueTo ( 'foo' ) ;
1423
+ expect ( inputElm ) . toBeDirty ( ) ;
1424
+ }
1425
+ } ) ;
1396
1426
1397
- expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1398
- expect ( inputElm ) . toBePristine ( ) ;
1427
+ it ( 'should not dirty the model on an input event in response to a interpolated placeholder change' , inject ( function ( $rootScope ) {
1428
+ if ( msie ) {
1429
+ compileInput ( '<input type="text" placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1430
+ browserTrigger ( inputElm , 'input' ) ;
1431
+ expect ( inputElm ) . toBePristine ( ) ;
1399
1432
1400
- inputElm . attr ( 'placeholder' , 'Test Again' ) ;
1401
- browserTrigger ( inputElm , 'input' ) ;
1433
+ $rootScope . ph = 1 ;
1434
+ $rootScope . $digest ( ) ;
1435
+ browserTrigger ( inputElm , 'input' ) ;
1436
+ expect ( inputElm ) . toBePristine ( ) ;
1402
1437
1403
- expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test Again' ) ;
1404
- expect ( inputElm ) . toBePristine ( ) ;
1405
- }
1406
- } ) ) ;
1438
+ $rootScope . ph = "" ;
1439
+ $rootScope . $digest ( ) ;
1440
+ browserTrigger ( inputElm , 'input' ) ;
1441
+ expect ( inputElm ) . toBePristine ( ) ;
1442
+
1443
+ changeInputValueTo ( 'foo' ) ;
1444
+ expect ( inputElm ) . toBeDirty ( ) ;
1445
+ }
1446
+ } ) ) ;
1447
+
1448
+ it ( 'should dirty the model on an input event in response to a placeholder change while in focus' , inject ( function ( $rootScope ) {
1449
+ if ( msie ) {
1450
+ $rootScope . ph = 'Test' ;
1451
+ compileInput ( '<input type="text" ng-attr-placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1452
+ expect ( inputElm ) . toBePristine ( ) ;
1453
+
1454
+ browserTrigger ( inputElm , 'focusin' ) ;
1455
+ browserTrigger ( inputElm , 'focus' ) ;
1456
+ browserTrigger ( inputElm , 'input' ) ;
1457
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1458
+ expect ( inputElm ) . toBePristine ( ) ;
1459
+
1460
+ $rootScope . ph = 'Test Again' ;
1461
+ $rootScope . $digest ( ) ;
1462
+ expect ( inputElm ) . toBePristine ( ) ;
1463
+
1464
+ changeInputValueTo ( 'foo' ) ;
1465
+ expect ( inputElm ) . toBeDirty ( ) ;
1466
+ }
1467
+ } ) ) ;
1468
+
1469
+ it ( 'should not dirty the model on an input event in response to a ng-attr-placeholder change' , inject ( function ( $rootScope ) {
1470
+ if ( msie ) {
1471
+ compileInput ( '<input type="text" ng-attr-placeholder="{{ph}}" ng-model="unsetValue" name="name" />' ) ;
1472
+ expect ( inputElm ) . toBePristine ( ) ;
1473
+
1474
+ $rootScope . ph = 1 ;
1475
+ $rootScope . $digest ( ) ;
1476
+ browserTrigger ( inputElm , 'input' ) ;
1477
+ expect ( inputElm ) . toBePristine ( ) ;
1478
+
1479
+ $rootScope . ph = "" ;
1480
+ $rootScope . $digest ( ) ;
1481
+ browserTrigger ( inputElm , 'input' ) ;
1482
+ expect ( inputElm ) . toBePristine ( ) ;
1483
+
1484
+ changeInputValueTo ( 'foo' ) ;
1485
+ expect ( inputElm ) . toBeDirty ( ) ;
1486
+ }
1487
+ } ) ) ;
1488
+
1489
+ it ( 'should not dirty the model on an input event in response to a focus' , inject ( function ( $sniffer ) {
1490
+ if ( msie ) {
1491
+ compileInput ( '<input type="text" placeholder="Test" ng-model="unsetValue" name="name" />' ) ;
1492
+ browserTrigger ( inputElm , 'input' ) ;
1493
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1494
+ expect ( inputElm ) . toBePristine ( ) ;
1495
+
1496
+ browserTrigger ( inputElm , 'focusin' ) ;
1497
+ browserTrigger ( inputElm , 'focus' ) ;
1498
+ browserTrigger ( inputElm , 'input' ) ;
1499
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1500
+ expect ( inputElm ) . toBePristine ( ) ;
1501
+
1502
+ changeInputValueTo ( 'foo' ) ;
1503
+ expect ( inputElm ) . toBeDirty ( ) ;
1504
+ }
1505
+ } ) ) ;
1506
+
1507
+ it ( 'should not dirty the model on an input event in response to a blur' , inject ( function ( $sniffer ) {
1508
+ if ( msie ) {
1509
+ compileInput ( '<input type="text" placeholder="Test" ng-model="unsetValue" name="name" />' ) ;
1510
+ browserTrigger ( inputElm , 'input' ) ;
1511
+ expect ( inputElm . attr ( 'placeholder' ) ) . toBe ( 'Test' ) ;
1512
+ expect ( inputElm ) . toBePristine ( ) ;
1513
+
1514
+ browserTrigger ( inputElm , 'focusin' ) ;
1515
+ browserTrigger ( inputElm , 'focus' ) ;
1516
+ browserTrigger ( inputElm , 'input' ) ;
1517
+ expect ( inputElm ) . toBePristine ( ) ;
1518
+
1519
+ browserTrigger ( inputElm , 'focusout' ) ;
1520
+ browserTrigger ( inputElm , 'input' ) ;
1521
+ browserTrigger ( inputElm , 'blur' ) ;
1522
+ expect ( inputElm ) . toBePristine ( ) ;
1523
+
1524
+ changeInputValueTo ( 'foo' ) ;
1525
+ expect ( inputElm ) . toBeDirty ( ) ;
1526
+ }
1527
+ } ) ) ;
1528
+
1529
+ it ( 'should dirty the model on an input event if there is a placeholder and value' , inject ( function ( $rootScope ) {
1530
+ if ( msie ) {
1531
+ $rootScope . name = 'foo' ;
1532
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1533
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1534
+ expect ( inputElm ) . toBePristine ( ) ;
1535
+
1536
+ changeInputValueTo ( 'bar' ) ;
1537
+ expect ( inputElm ) . toBeDirty ( ) ;
1538
+ }
1539
+ } ) ) ;
1540
+
1541
+ it ( 'should dirty the model on an input event if there is a placeholder and value after focusing' , inject ( function ( $rootScope ) {
1542
+ if ( msie ) {
1543
+ $rootScope . name = 'foo' ;
1544
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1545
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1546
+ expect ( inputElm ) . toBePristine ( ) ;
1547
+
1548
+ browserTrigger ( inputElm , 'focusin' ) ;
1549
+ browserTrigger ( inputElm , 'focus' ) ;
1550
+ changeInputValueTo ( 'bar' ) ;
1551
+ expect ( inputElm ) . toBeDirty ( ) ;
1552
+ }
1553
+ } ) ) ;
1554
+
1555
+ it ( 'should dirty the model on an input event if there is a placeholder and value after bluring' , inject ( function ( $rootScope ) {
1556
+ if ( msie ) {
1557
+ $rootScope . name = 'foo' ;
1558
+ compileInput ( '<input type="text" placeholder="Test" ng-model="name" value="init" name="name" />' ) ;
1559
+ expect ( inputElm . val ( ) ) . toBe ( $rootScope . name ) ;
1560
+ expect ( inputElm ) . toBePristine ( ) ;
1561
+
1562
+ browserTrigger ( inputElm , 'focusin' ) ;
1563
+ browserTrigger ( inputElm , 'focus' ) ;
1564
+ expect ( inputElm ) . toBePristine ( ) ;
1565
+
1566
+ browserTrigger ( inputElm , 'focusout' ) ;
1567
+ browserTrigger ( inputElm , 'blur' ) ;
1568
+ changeInputValueTo ( 'bar' ) ;
1569
+ expect ( inputElm ) . toBeDirty ( ) ;
1570
+ }
1571
+ } ) ) ;
1572
+ } ) ;
1407
1573
1408
1574
1409
1575
it ( 'should interpolate input names' , function ( ) {
0 commit comments