1
1
/*!
2
- * vue-validator v2.1.1
2
+ * vue-validator v2.1.2
3
3
* (c) 2016 kazuya kawaguchi
4
4
* Released under the MIT License.
5
5
*/
@@ -567,7 +567,7 @@ function Validate (Vue) {
567
567
var el = this . el ;
568
568
569
569
if ( process . env . NODE_ENV !== 'production' && el . __vue__ ) {
570
- warn ( 'v-validate="' + this . expression + '" cannot be ' + ' used on an instance root element.') ;
570
+ warn ( 'v-validate="' + this . expression + '" cannot be used on an instance root element.' ) ;
571
571
this . _invalid = true ;
572
572
return ;
573
573
}
@@ -1245,28 +1245,13 @@ var BaseValidation = function () {
1245
1245
var future = validator . call ( this , val , arg ) ;
1246
1246
if ( typeof future === 'function' ) {
1247
1247
// function
1248
- if ( future . resolved ) {
1249
- // cached
1250
- cb ( future . resolved ) ;
1251
- } else if ( future . requested ) {
1252
- // pool callbacks
1253
- future . pendingCallbacks . push ( cb ) ;
1254
- } else {
1255
- ( function ( ) {
1256
- future . requested = true ;
1257
- var cbs = future . pendingCallbacks = [ cb ] ;
1258
- future ( function ( ) {
1259
- // resolve
1260
- future . resolved = true ;
1261
- for ( var i = 0 , l = cbs . length ; i < l ; i ++ ) {
1262
- cbs [ i ] ( true ) ;
1263
- }
1264
- } , function ( msg ) {
1265
- // reject
1266
- cb ( false , msg ) ;
1267
- } ) ;
1268
- } ) ( ) ;
1269
- }
1248
+ future ( function ( ) {
1249
+ // resolve
1250
+ cb ( true ) ;
1251
+ } , function ( msg ) {
1252
+ // reject
1253
+ cb ( false , msg ) ;
1254
+ } ) ;
1270
1255
} else if ( isPromise ( future ) ) {
1271
1256
// promise
1272
1257
future . then ( function ( ) {
@@ -1845,20 +1830,31 @@ var Validator$1 = function () {
1845
1830
1846
1831
Validator . prototype . disableReactive = function disableReactive ( ) {
1847
1832
var vm = this . _dir . vm ;
1848
- vm . $setValidationErrors = undefined ;
1849
- vm . $validate = undefined ;
1850
- vm . $validatorReset = undefined ;
1833
+ vm . $setValidationErrors = null ;
1834
+ delete vm [ '$setValidationErrors' ] ;
1835
+ vm . $validate = null ;
1836
+ delete vm [ '$validate' ] ;
1837
+ vm . $validatorReset = null ;
1838
+ delete vm [ '$validatorReset' ] ;
1851
1839
vm . _validatorMaps [ this . name ] = null ;
1840
+ delete vm . _validatorMaps [ this . name ] ;
1852
1841
vm [ this . name ] = null ;
1842
+ delete vm [ this . name ] ;
1853
1843
} ;
1854
1844
1855
1845
Validator . prototype . registerEvents = function registerEvents ( ) {
1846
+ var isSimplePath = exports$1 . Vue . parsers . expression . isSimplePath ;
1847
+
1856
1848
var attrs = this . _dir . el . attributes ;
1857
1849
for ( var i = 0 , l = attrs . length ; i < l ; i ++ ) {
1858
1850
var event = attrs [ i ] . name ;
1859
1851
if ( REGEX_EVENT . test ( event ) ) {
1852
+ var value = attrs [ i ] . value ;
1853
+ if ( isSimplePath ( value ) ) {
1854
+ value += '.apply(this, $arguments)' ;
1855
+ }
1860
1856
event = event . replace ( REGEX_EVENT , '' ) ;
1861
- this . _events [ this . _getEventName ( event ) ] = this . _dir . vm . $eval ( attrs [ i ] . value , true ) ;
1857
+ this . _events [ this . _getEventName ( event ) ] = this . _dir . vm . $eval ( value , true ) ;
1862
1858
}
1863
1859
}
1864
1860
} ;
@@ -1905,14 +1901,14 @@ var Validator$1 = function () {
1905
1901
Validator . prototype . addGroupValidation = function addGroupValidation ( group , field ) {
1906
1902
var indexOf = exports$1 . Vue . util . indexOf ;
1907
1903
1908
- var validation = this . _validations [ field ] || this . _checkboxValidations [ field ] . validation || this . _radioValidations [ field ] . validation ;
1904
+ var validation = this . _getValidationFrom ( field ) ;
1909
1905
var validations = this . _groupValidations [ group ] ;
1910
1906
1911
1907
validations && ! ~ indexOf ( validations , validation ) && validations . push ( validation ) ;
1912
1908
} ;
1913
1909
1914
1910
Validator . prototype . removeGroupValidation = function removeGroupValidation ( group , field ) {
1915
- var validation = this . _validations [ field ] || this . _checkboxValidations [ field ] . validation || this . _radioValidations [ field ] . validation ;
1911
+ var validation = this . _getValidationFrom ( field ) ;
1916
1912
var validations = this . _groupValidations [ group ] ;
1917
1913
1918
1914
validations && pull ( validations , validation ) ;
@@ -2057,13 +2053,7 @@ var Validator$1 = function () {
2057
2053
} ;
2058
2054
2059
2055
Validator . prototype . _getValidationFrom = function _getValidationFrom ( field ) {
2060
- var validation = this . _validations [ field ] ;
2061
- if ( ! validation && this . _checkboxValidations [ field ] ) {
2062
- validation = this . _checkboxValidations [ field ] . validation ;
2063
- } else if ( ! validation && this . _radioValidations [ field ] ) {
2064
- validation = this . _radioValidations [ field ] . validation ;
2065
- }
2066
- return validation ;
2056
+ return this . _validations [ field ] || this . _checkboxValidations [ field ] && this . _checkboxValidations [ field ] . validation || this . _radioValidations [ field ] && this . _radioValidations [ field ] . validation ;
2067
2057
} ;
2068
2058
2069
2059
Validator . prototype . _resetValidation = function _resetValidation ( cb ) {
@@ -2079,6 +2069,7 @@ var Validator$1 = function () {
2079
2069
var extend = exports$1 . Vue . util . extend ;
2080
2070
2081
2071
// make tempolaly errors
2072
+
2082
2073
var temp = { } ;
2083
2074
each ( errors , function ( error , index ) {
2084
2075
if ( ! temp [ error . field ] ) {
@@ -2089,18 +2080,24 @@ var Validator$1 = function () {
2089
2080
2090
2081
// set errors
2091
2082
each ( temp , function ( values , field ) {
2092
- var validation = _this9 . _scope [ field ] ;
2093
- var newValidation = { } ;
2083
+ var results = _this9 . _scope [ field ] ;
2084
+ var newResults = { } ;
2085
+
2094
2086
each ( values , function ( error ) {
2095
2087
if ( error . validator ) {
2096
- validation [ error . validator ] = error . message ;
2088
+ results [ error . validator ] = error . message ;
2097
2089
}
2098
2090
} ) ;
2099
- validation . valid = false ;
2100
- validation . invalid = true ;
2101
- validation . errors = values ;
2102
- extend ( newValidation , validation ) ;
2103
- exports$1 . Vue . set ( _this9 . _scope , field , newValidation ) ;
2091
+
2092
+ results . valid = false ;
2093
+ results . invalid = true ;
2094
+ results . errors = values ;
2095
+ extend ( newResults , results ) ;
2096
+
2097
+ var validation = _this9 . _getValidationFrom ( field ) ;
2098
+ validation . willUpdateClasses ( newResults , validation . el ) ;
2099
+
2100
+ exports$1 . Vue . set ( _this9 . _scope , field , newResults ) ;
2104
2101
} ) ;
2105
2102
} ;
2106
2103
@@ -2189,13 +2186,14 @@ var Validator$1 = function () {
2189
2186
} ;
2190
2187
2191
2188
Validator . prototype . _fireEvent = function _fireEvent ( type ) {
2192
- var handler = this . _events [ this . _getEventName ( type ) ] ;
2193
-
2194
2189
for ( var _len2 = arguments . length , args = Array ( _len2 > 1 ? _len2 - 1 : 0 ) , _key2 = 1 ; _key2 < _len2 ; _key2 ++ ) {
2195
2190
args [ _key2 - 1 ] = arguments [ _key2 ] ;
2196
2191
}
2197
2192
2198
- handler && handler . apply ( null , args ) ;
2193
+ var handler = this . _events [ this . _getEventName ( type ) ] ;
2194
+ handler && this . _dir . vm . $nextTick ( function ( ) {
2195
+ handler . apply ( null , args ) ;
2196
+ } ) ;
2199
2197
} ;
2200
2198
2201
2199
Validator . prototype . _fireEvents = function _fireEvents ( ) {
@@ -2330,7 +2328,9 @@ var Validator$1 = function () {
2330
2328
}
2331
2329
} ) ;
2332
2330
2333
- return empty ( errors ) ? undefined : errors ;
2331
+ return empty ( errors ) ? undefined : errors . sort ( function ( a , b ) {
2332
+ return a . field < b . field ? - 1 : 1 ;
2333
+ } ) ;
2334
2334
} ;
2335
2335
2336
2336
babelHelpers . createClass ( Validator , [ {
@@ -2587,7 +2587,7 @@ function plugin(Vue) {
2587
2587
Validate ( Vue ) ;
2588
2588
}
2589
2589
2590
- plugin . version = '2.1.1 ' ;
2590
+ plugin . version = '2.1.2 ' ;
2591
2591
2592
2592
if ( typeof window !== 'undefined' && window . Vue ) {
2593
2593
window . Vue . use ( plugin ) ;
0 commit comments