@@ -1556,6 +1556,10 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1556
1556
1557
1557
var minVal = 0 ,
1558
1558
maxVal = 100 ,
1559
+ stepVal = 1 ,
1560
+ minAttrType = isDefined ( attr . ngMin ) ? 'ngMin' : isDefined ( attr . min ) ? 'min' : false ,
1561
+ maxAttrType = isDefined ( attr . ngMax ) ? 'ngMax' : isDefined ( attr . max ) ? 'max' : false ,
1562
+ stepAttributeType = isDefined ( attr . ngStep ) ? 'ngStep' : isDefined ( attr . step ) ? 'step' : false ,
1559
1563
supportsRange = ctrl . $$hasNativeValidators && element [ 0 ] . type === 'range' ,
1560
1564
validity = element [ 0 ] . validity ;
1561
1565
@@ -1570,6 +1574,55 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1570
1574
} :
1571
1575
originalRender ;
1572
1576
1577
+ if ( minAttrType ) {
1578
+ ctrl . $validators . min = minAttrType === 'min' && supportsRange ?
1579
+ function noopMinValidator ( value ) {
1580
+ // Since all browsers set the input to a valid value, we don't need to check validity
1581
+ return true ;
1582
+ } :
1583
+ // ngMin doesn't set the min attr, so the browser doesn't adjust the input value as setting min would
1584
+ function minValidator ( modelValue , viewValue ) {
1585
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1586
+ } ;
1587
+
1588
+ // Assign minVal when the directive is linked. This won't run the validators as the model isn't ready yet
1589
+ minChange ( attr . min ) ;
1590
+ attr . $observe ( 'min' , minChange ) ;
1591
+ }
1592
+
1593
+ if ( maxAttrType ) {
1594
+ ctrl . $validators . max = maxAttrType === 'max' && supportsRange ?
1595
+ function noopMaxValidator ( ) {
1596
+ // Since all browsers set the input to a valid value, we don't need to check validity
1597
+ return true ;
1598
+ } :
1599
+ // ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
1600
+ function maxValidator ( modelValue , viewValue ) {
1601
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1602
+ } ;
1603
+
1604
+ // Assign maxVal when the directive is linked. This won't run the validators as the model isn't ready yet
1605
+ maxChange ( attr . max ) ;
1606
+ attr . $observe ( 'max' , maxChange ) ;
1607
+
1608
+ }
1609
+
1610
+ if ( stepAttributeType ) {
1611
+ ctrl . $validators . step = stepAttributeType === 'step' && supportsRange ?
1612
+ function noopStepValidator ( ) {
1613
+ // Since all browsers set the input to a valid value, we don't need to check validity
1614
+ return true ;
1615
+ } :
1616
+ // ngStep doesn't set the setp attr, so the browser doesn't adjust the input value as setting step would
1617
+ function stepValidator ( modelValue , viewValue ) {
1618
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( stepVal ) || viewValue % stepVal === 0 ;
1619
+ } ;
1620
+
1621
+ // Assign stepVal when the directive is linked. This won't run the validators as the model isn't ready yet
1622
+ stepChange ( attr . step ) ;
1623
+ attr . $observe ( 'step' , stepChange ) ;
1624
+ }
1625
+
1573
1626
function minChange ( val ) {
1574
1627
if ( isDefined ( val ) && ! isNumber ( val ) ) {
1575
1628
val = parseFloat ( val ) ;
@@ -1594,23 +1647,6 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1594
1647
}
1595
1648
}
1596
1649
1597
- var minAttrType = isDefined ( attr . ngMin ) ? 'ngMin' : isDefined ( attr . min ) ? 'min' : false ;
1598
- if ( minAttrType ) {
1599
- ctrl . $validators . min = isDefined ( attr . min ) && supportsRange ?
1600
- function noopMinValidator ( value ) {
1601
- // Since all browsers set the input to a valid value, we don't need to check validity
1602
- return true ;
1603
- } :
1604
- // ngMin doesn't set the min attr, so the browser doesn't adjust the input value as setting min would
1605
- function minValidator ( modelValue , viewValue ) {
1606
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1607
- } ;
1608
-
1609
- // Assign minVal when the directive is linked. This won't run the validators as the model isn't ready yet
1610
- minChange ( attr . min ) ;
1611
- attr . $observe ( 'min' , minChange ) ;
1612
- }
1613
-
1614
1650
function maxChange ( val ) {
1615
1651
if ( isDefined ( val ) && ! isNumber ( val ) ) {
1616
1652
val = parseFloat ( val ) ;
@@ -1634,23 +1670,24 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1634
1670
ctrl . $validate ( ) ;
1635
1671
}
1636
1672
}
1637
- var maxAttrType = isDefined ( attr . max ) ? 'max' : attr . ngMax ? 'ngMax' : false ;
1638
- if ( maxAttrType ) {
1639
- ctrl . $validators . max = isDefined ( attr . max ) && supportsRange ?
1640
- function noopMaxValidator ( ) {
1641
- // Since all browsers set the input to a valid value, we don't need to check validity
1642
- return true ;
1643
- } :
1644
- // ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
1645
- function maxValidator ( modelValue , viewValue ) {
1646
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1647
- } ;
1648
1673
1649
- // Assign maxVal when the directive is linked. This won't run the validators as the model isn't ready yet
1650
- maxChange ( attr . max ) ;
1651
- attr . $observe ( 'max' , maxChange ) ;
1652
- }
1674
+ function stepChange ( val ) {
1675
+ if ( isDefined ( val ) && ! isNumber ( val ) ) {
1676
+ val = parseFloat ( val ) ;
1677
+ }
1678
+ stepVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1679
+ // ignore changes before model is initialized
1680
+ if ( isNumber ( ctrl . $modelValue ) && isNaN ( ctrl . $modelValue ) ) {
1681
+ return ;
1682
+ }
1653
1683
1684
+ if ( supportsRange && stepAttributeType === 'step' ) {
1685
+ ctrl . $setViewValue ( element . val ( ) ) ;
1686
+ } else {
1687
+ // TODO(matsko): implement validateLater to reduce number of validations
1688
+ ctrl . $validate ( ) ;
1689
+ }
1690
+ }
1654
1691
}
1655
1692
1656
1693
function urlInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
0 commit comments