File tree 2 files changed +6
-15
lines changed
2 files changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -2131,21 +2131,12 @@ var requiredDirective = function() {
2131
2131
if ( ! ctrl ) return ;
2132
2132
attr . required = true ; // force truthy in case we are on non input element
2133
2133
2134
- var validator = function ( value ) {
2135
- if ( attr . required && ctrl . $isEmpty ( value ) ) {
2136
- ctrl . $setValidity ( 'required' , false ) ;
2137
- return ;
2138
- } else {
2139
- ctrl . $setValidity ( 'required' , true ) ;
2140
- return value ;
2141
- }
2134
+ ctrl . $validators . required = function ( value ) {
2135
+ return ! attr . required || ! ctrl . $isEmpty ( value ) ;
2142
2136
} ;
2143
2137
2144
- ctrl . $formatters . push ( validator ) ;
2145
- ctrl . $parsers . unshift ( validator ) ;
2146
-
2147
2138
attr . $observe ( 'required' , function ( ) {
2148
- validator ( ctrl . $viewValue ) ;
2139
+ ctrl . $validateLater ( ) ;
2149
2140
} ) ;
2150
2141
}
2151
2142
} ;
Original file line number Diff line number Diff line change @@ -2396,7 +2396,7 @@ describe('input', function() {
2396
2396
it ( 'should be invalid if required and empty' , function ( ) {
2397
2397
compileInput ( '<input type="text" ng-list ng-model="list" required>' ) ;
2398
2398
changeInputValueTo ( '' ) ;
2399
- expect ( scope . list ) . toBeUndefined ( ) ;
2399
+ expect ( scope . list ) . toEqual ( [ ] ) ;
2400
2400
expect ( inputElm ) . toBeInvalid ( ) ;
2401
2401
changeInputValueTo ( 'a,b' ) ;
2402
2402
expect ( scope . list ) . toEqual ( [ 'a' , 'b' ] ) ;
@@ -2470,7 +2470,7 @@ describe('input', function() {
2470
2470
} ) ;
2471
2471
2472
2472
2473
- it ( 'should be $invalid but $pristine if not touched ' , function ( ) {
2473
+ it ( 'should be considered $pristine if the value is empty ' , function ( ) {
2474
2474
compileInput ( '<input type="text" ng-model="name" name="alias" required />' ) ;
2475
2475
2476
2476
scope . $apply ( function ( ) {
@@ -2482,7 +2482,7 @@ describe('input', function() {
2482
2482
2483
2483
changeInputValueTo ( '' ) ;
2484
2484
expect ( inputElm ) . toBeInvalid ( ) ;
2485
- expect ( inputElm ) . toBeDirty ( ) ;
2485
+ expect ( inputElm ) . toBePristine ( ) ;
2486
2486
} ) ;
2487
2487
2488
2488
You can’t perform that action at this time.
0 commit comments