@@ -8,14 +8,24 @@ export default {
88 'validationField' ,
99 'validationMessages'
1010 ] ,
11+ computed : {
12+ isReadOnly ( ) {
13+ if ( this . readonly || this . disabled || this . $attrs . readonly || this . $attrs . disabled ) {
14+ return true ;
15+ } else {
16+ return false ;
17+ }
18+ }
19+ } ,
1120 data ( ) {
1221 return {
1322 validator : null
1423 }
1524 } ,
1625 mounted ( ) {
1726 this . setValidatorLanguage ( ) ;
18- this . updateValidation ( )
27+ this . updateValidation ( ) ;
28+ this . observeElementMutations ( ) ;
1929 } ,
2030 watch : {
2131 // Triggered whenever the v-model is updated
@@ -29,6 +39,12 @@ export default {
2939 label ( ) {
3040 this . updateValidation ( )
3141 } ,
42+ readonly ( ) {
43+ this . updateValidation ( ) ;
44+ } ,
45+ disabled ( ) {
46+ this . updateValidation ( ) ;
47+ } ,
3248 validationData : {
3349 handler : function ( ) {
3450 this . updateValidation ( )
@@ -37,6 +53,20 @@ export default {
3753 }
3854 } ,
3955 methods : {
56+ observeElementMutations ( ) {
57+ new MutationObserver ( this . handleMutations ) . observe ( this . $el , {
58+ attributes : true ,
59+ attributeFilter : [ 'readonly' , 'disabled' ] ,
60+ subtree : true
61+ } ) ;
62+ } ,
63+ handleMutations ( mutations ) {
64+ mutations . forEach ( mutation => {
65+ if ( mutation . type == "attributes" ) {
66+ this . updateValidation ( )
67+ }
68+ } ) ;
69+ } ,
4070 setValidatorLanguage ( ) {
4171 let globalObject = typeof window === 'undefined' ? global : window ;
4272
@@ -53,7 +83,7 @@ export default {
5383 globalObject . validatorLanguageSet = true ;
5484 } ,
5585 updateValidation ( ) {
56- if ( this . validation ) {
86+ if ( this . validation && ! this . isReadOnly ) {
5787 let fieldName = this . validationField ? this . validationField : this . name ;
5888 let data = this . validationData ? this . validationData : { [ fieldName ] : this . value }
5989 let validationRules = '' ;
0 commit comments