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