@@ -1497,7 +1497,7 @@ function createDateParser(regexp, mapping) {
1497
1497
}
1498
1498
1499
1499
function createDateInputType ( type , regexp , parseDate , format ) {
1500
- return function dynamicDateInputType ( scope , element , attr , ctrl , $sniffer , $browser , $filter ) {
1500
+ return function dynamicDateInputType ( scope , element , attr , ctrl , $sniffer , $browser , $filter , $parse ) {
1501
1501
badInputChecker ( scope , element , attr , ctrl , type ) ;
1502
1502
baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1503
1503
@@ -1540,24 +1540,35 @@ function createDateInputType(type, regexp, parseDate, format) {
1540
1540
} ) ;
1541
1541
1542
1542
if ( isDefined ( attr . min ) || attr . ngMin ) {
1543
- var minVal ;
1543
+ var minVal = attr . min || $parse ( attr . ngMin ) ( scope ) ;
1544
+ var parsedMinVal = parseObservedDateValue ( minVal ) ;
1545
+
1544
1546
ctrl . $validators . min = function ( value ) {
1545
- return ! isValidDate ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1547
+ return ! isValidDate ( value ) || isUndefined ( parsedMinVal ) || parseDate ( value ) >= parsedMinVal ;
1546
1548
} ;
1547
1549
attr . $observe ( 'min' , function ( val ) {
1548
- minVal = parseObservedDateValue ( val ) ;
1549
- ctrl . $validate ( ) ;
1550
+ if ( val !== minVal ) {
1551
+ parsedMinVal = parseObservedDateValue ( val ) ;
1552
+ ctrl . $validate ( ) ;
1553
+ }
1554
+ minVal = val ;
1550
1555
} ) ;
1551
1556
}
1552
1557
1553
1558
if ( isDefined ( attr . max ) || attr . ngMax ) {
1554
- var maxVal ;
1559
+ var maxVal = attr . max || $parse ( attr . ngMax ) ( scope ) ;
1560
+ var parsedMaxVal = parseObservedDateValue ( maxVal ) ;
1561
+
1555
1562
ctrl . $validators . max = function ( value ) {
1556
- return ! isValidDate ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1563
+ return ! isValidDate ( value ) || isUndefined ( parsedMaxVal ) || parseDate ( value ) <= parsedMaxVal ;
1557
1564
} ;
1558
1565
attr . $observe ( 'max' , function ( val ) {
1559
- maxVal = parseObservedDateValue ( val ) ;
1560
- ctrl . $validate ( ) ;
1566
+ if ( val !== maxVal ) {
1567
+ parsedMaxVal = parseObservedDateValue ( val ) ;
1568
+ ctrl . $validate ( ) ;
1569
+ }
1570
+
1571
+ maxVal = val ;
1561
1572
} ) ;
1562
1573
}
1563
1574
@@ -1709,50 +1720,68 @@ function isValidForStep(viewValue, stepBase, step) {
1709
1720
return ( value - stepBase ) % step === 0 ;
1710
1721
}
1711
1722
1712
- function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1723
+ function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser , $filter , $parse ) {
1713
1724
badInputChecker ( scope , element , attr , ctrl , 'number' ) ;
1714
1725
numberFormatterParser ( ctrl ) ;
1715
1726
baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1716
1727
1717
- var minVal ;
1718
- var maxVal ;
1728
+ var parsedMinVal ;
1719
1729
1720
1730
if ( isDefined ( attr . min ) || attr . ngMin ) {
1731
+ var minVal = attr . min || $parse ( attr . ngMin ) ( scope ) ;
1732
+ parsedMinVal = parseNumberAttrVal ( minVal ) ;
1733
+
1721
1734
ctrl . $validators . min = function ( modelValue , viewValue ) {
1722
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1735
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( parsedMinVal ) || viewValue >= parsedMinVal ;
1723
1736
} ;
1724
1737
1725
1738
attr . $observe ( 'min' , function ( val ) {
1726
- minVal = parseNumberAttrVal ( val ) ;
1727
- // TODO(matsko): implement validateLater to reduce number of validations
1728
- ctrl . $validate ( ) ;
1739
+ if ( val !== minVal ) {
1740
+ parsedMinVal = parseNumberAttrVal ( val ) ;
1741
+ // TODO(matsko): implement validateLater to reduce number of validations
1742
+ ctrl . $validate ( ) ;
1743
+ }
1744
+ minVal = val ;
1729
1745
} ) ;
1730
1746
}
1731
1747
1732
1748
if ( isDefined ( attr . max ) || attr . ngMax ) {
1749
+ var maxVal = attr . max || $parse ( attr . ngMax ) ( scope ) ;
1750
+ var parsedMaxVal = parseNumberAttrVal ( maxVal ) ;
1751
+
1733
1752
ctrl . $validators . max = function ( modelValue , viewValue ) {
1734
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1753
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( parsedMaxVal ) || viewValue <= parsedMaxVal ;
1735
1754
} ;
1736
1755
1737
1756
attr . $observe ( 'max' , function ( val ) {
1738
- maxVal = parseNumberAttrVal ( val ) ;
1739
- // TODO(matsko): implement validateLater to reduce number of validations
1740
- ctrl . $validate ( ) ;
1757
+ if ( val !== maxVal ) {
1758
+ parsedMaxVal = parseNumberAttrVal ( val ) ;
1759
+ // TODO(matsko): implement validateLater to reduce number of validations
1760
+ ctrl . $validate ( ) ;
1761
+ }
1762
+ maxVal = val ;
1741
1763
} ) ;
1742
1764
}
1743
1765
1744
1766
if ( isDefined ( attr . step ) || attr . ngStep ) {
1745
- var stepVal ;
1767
+ var stepVal = attr . step || $parse ( attr . ngStep ) ( scope ) ;
1768
+ var parsedStepVal = parseNumberAttrVal ( stepVal ) ;
1769
+
1746
1770
ctrl . $validators . step = function ( modelValue , viewValue ) {
1747
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( stepVal ) ||
1748
- isValidForStep ( viewValue , minVal || 0 , stepVal ) ;
1771
+ return ctrl . $isEmpty ( viewValue ) || isUndefined ( parsedStepVal ) ||
1772
+ isValidForStep ( viewValue , parsedMinVal || 0 , parsedStepVal ) ;
1749
1773
} ;
1750
1774
1751
1775
attr . $observe ( 'step' , function ( val ) {
1752
- stepVal = parseNumberAttrVal ( val ) ;
1753
1776
// TODO(matsko): implement validateLater to reduce number of validations
1754
- ctrl . $validate ( ) ;
1777
+ if ( stepVal !== val ) {
1778
+ parsedStepVal = parseNumberAttrVal ( val ) ;
1779
+ ctrl . $validate ( ) ;
1780
+ }
1781
+
1782
+ stepVal = val ;
1755
1783
} ) ;
1784
+
1756
1785
}
1757
1786
}
1758
1787
@@ -1782,6 +1811,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1782
1811
originalRender ;
1783
1812
1784
1813
if ( hasMinAttr ) {
1814
+ minVal = parseNumberAttrVal ( attr . min ) ;
1815
+
1785
1816
ctrl . $validators . min = supportsRange ?
1786
1817
// Since all browsers set the input to a valid value, we don't need to check validity
1787
1818
function noopMinValidator ( ) { return true ; } :
@@ -1794,6 +1825,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1794
1825
}
1795
1826
1796
1827
if ( hasMaxAttr ) {
1828
+ maxVal = parseNumberAttrVal ( attr . max ) ;
1829
+
1797
1830
ctrl . $validators . max = supportsRange ?
1798
1831
// Since all browsers set the input to a valid value, we don't need to check validity
1799
1832
function noopMaxValidator ( ) { return true ; } :
@@ -1806,6 +1839,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1806
1839
}
1807
1840
1808
1841
if ( hasStepAttr ) {
1842
+ stepVal = parseNumberAttrVal ( attr . step ) ;
1843
+
1809
1844
ctrl . $validators . step = supportsRange ?
1810
1845
function nativeStepValidator ( ) {
1811
1846
// Currently, only FF implements the spec on step change correctly (i.e. adjusting the
@@ -1827,7 +1862,13 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1827
1862
// attribute value when the input is first rendered, so that the browser can adjust the
1828
1863
// input value based on the min/max value
1829
1864
element . attr ( htmlAttrName , attr [ htmlAttrName ] ) ;
1830
- attr . $observe ( htmlAttrName , changeFn ) ;
1865
+ var oldVal = attr [ htmlAttrName ] ;
1866
+ attr . $observe ( htmlAttrName , function wrappedObserver ( val ) {
1867
+ if ( val !== oldVal ) {
1868
+ changeFn ( val ) ;
1869
+ }
1870
+ oldVal = val ;
1871
+ } ) ;
1831
1872
}
1832
1873
1833
1874
function minChange ( val ) {
@@ -1881,11 +1922,11 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1881
1922
}
1882
1923
1883
1924
// Some browsers don't adjust the input value correctly, but set the stepMismatch error
1884
- if ( supportsRange && ctrl . $viewValue !== element . val ( ) ) {
1885
- ctrl . $setViewValue ( element . val ( ) ) ;
1886
- } else {
1925
+ if ( ! supportsRange ) {
1887
1926
// TODO(matsko): implement validateLater to reduce number of validations
1888
1927
ctrl . $validate ( ) ;
1928
+ } else if ( ctrl . $viewValue !== element . val ( ) ) {
1929
+ ctrl . $setViewValue ( element . val ( ) ) ;
1889
1930
}
1890
1931
}
1891
1932
}
0 commit comments