@@ -983,6 +983,7 @@ describe('ngModel', function() {
983
983
984
984
describe ( 'input' , function ( ) {
985
985
var formElm , inputElm , scope , $compile , $sniffer , $browser , changeInputValueTo , currentSpec ;
986
+ var compileProvider ;
986
987
987
988
function compileInput ( inputHtml , mockValidity ) {
988
989
inputElm = jqLite ( inputHtml ) ;
@@ -1002,8 +1003,9 @@ describe('input', function() {
1002
1003
var attrs ;
1003
1004
beforeEach ( function ( ) { currentSpec = this ; } ) ;
1004
1005
afterEach ( function ( ) { currentSpec = null ; } ) ;
1005
- beforeEach ( module ( function ( $compileProvider ) {
1006
- $compileProvider . directive ( 'attrCapture' , function ( ) {
1006
+ beforeEach ( module ( function ( $compileProvider , $exceptionHandlerProvider ) {
1007
+ compileProvider = $compileProvider ;
1008
+ compileProvider . directive ( 'attrCapture' , function ( ) {
1007
1009
return function ( scope , element , $attrs ) {
1008
1010
attrs = $attrs ;
1009
1011
} ;
@@ -1865,6 +1867,40 @@ describe('input', function() {
1865
1867
1866
1868
describe ( 'maxlength' , function ( ) {
1867
1869
1870
+ it ( 'should validate after minlength attr being observed' , function ( ) {
1871
+
1872
+ var actualCalls = [ ] ;
1873
+ var expectedCalls = [ "X-Observe" , "X-Validate" ] ;
1874
+
1875
+ compileProvider
1876
+ . directive ( 'ngMinlengthX' , function ( ) {
1877
+ return {
1878
+ restrict : 'A' ,
1879
+ require : '?ngModel' ,
1880
+ link : function ( scope , elm , attr , ctrl ) {
1881
+ if ( ! ctrl )
1882
+ return ;
1883
+
1884
+ var minlength = 0 ;
1885
+ attr . $observe ( 'minlength' , function ( value ) {
1886
+ actualCalls . push ( "[X-Observe]" ) ;
1887
+ minlength = int ( value ) || 0 ;
1888
+ ctrl . $validate ( ) ;
1889
+ } ) ;
1890
+
1891
+ ctrl . $validators . minlength = function ( modelValue , viewValue ) {
1892
+ actualCalls . push ( "[X-Validate]" ) ;
1893
+ return ctrl . $isEmpty ( viewValue ) || viewValue . length >= minlength ;
1894
+ } ;
1895
+ }
1896
+ } ;
1897
+ } ) ;
1898
+
1899
+ compileInput ( '<input type="text" ng-model="value" ng-minlength-x="5"/>' ) ;
1900
+
1901
+ expect ( actualCalls ) . toEqual ( expectedCalls ) ;
1902
+ } ) ;
1903
+
1868
1904
it ( 'should invalidate values that are longer than the given maxlength' , function ( ) {
1869
1905
compileInput ( '<input type="text" ng-model="value" ng-maxlength="5" />' ) ;
1870
1906
0 commit comments