@@ -32,6 +32,12 @@ var WEEK_REGEXP = /^(\d{4})-W(\d\d)$/;
32
32
var MONTH_REGEXP = / ^ ( \d { 4 } ) - ( \d \d ) $ / ;
33
33
var TIME_REGEXP = / ^ ( \d \d ) : ( \d \d ) (?: : ( \d \d ) ( \. \d { 1 , 3 } ) ? ) ? $ / ;
34
34
35
+ var PARTIAL_VALIDATION_EVENTS = 'keydown wheel mousedown' ;
36
+ var PARTIAL_VALIDATION_TYPES = createMap ( ) ;
37
+ forEach ( 'date,datetime-local,month,time,week' . split ( ',' ) , function ( type ) {
38
+ PARTIAL_VALIDATION_TYPES [ type ] = true ;
39
+ } ) ;
40
+
35
41
var inputType = {
36
42
37
43
/**
@@ -1118,6 +1124,8 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1118
1124
} ) ;
1119
1125
}
1120
1126
1127
+ var timeout ;
1128
+
1121
1129
var listener = function ( ev ) {
1122
1130
if ( timeout ) {
1123
1131
$browser . defer . cancel ( timeout ) ;
@@ -1147,8 +1155,6 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1147
1155
if ( $sniffer . hasEvent ( 'input' ) ) {
1148
1156
element . on ( 'input' , listener ) ;
1149
1157
} else {
1150
- var timeout ;
1151
-
1152
1158
var deferListener = function ( ev , input , origValue ) {
1153
1159
if ( ! timeout ) {
1154
1160
timeout = $browser . defer ( function ( ) {
@@ -1180,6 +1186,26 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1180
1186
// or form autocomplete on newer browser, we need "change" event to catch it
1181
1187
element . on ( 'change' , listener ) ;
1182
1188
1189
+ // Some native input types (date-family) have the ability to change validity without
1190
+ // firing any input/change events.
1191
+ // For these event types, when native validators are present and the browser supports the type,
1192
+ // check for validity changes on various DOM events.
1193
+ if ( PARTIAL_VALIDATION_TYPES [ type ] && ctrl . $$hasNativeValidators && type === attr . type ) {
1194
+ element . on ( PARTIAL_VALIDATION_EVENTS , function ( ev ) {
1195
+ if ( ! timeout ) {
1196
+ var validity = this [ VALIDITY_STATE_PROPERTY ] || { } ;
1197
+ var origBadInput = validity . badInput ;
1198
+ var origTypeMismatch = validity . typeMismatch ;
1199
+ timeout = $browser . defer ( function ( ) {
1200
+ timeout = null ;
1201
+ if ( validity . badInput !== origBadInput || validity . typeMismatch !== origTypeMismatch ) {
1202
+ listener ( ev ) ;
1203
+ }
1204
+ } ) ;
1205
+ }
1206
+ } ) ;
1207
+ }
1208
+
1183
1209
ctrl . $render = function ( ) {
1184
1210
// Workaround for Firefox validation #12102.
1185
1211
var value = ctrl . $isEmpty ( ctrl . $viewValue ) ? '' : ctrl . $viewValue ;
0 commit comments