Can I access a data element in a rule
?
I'm trying to flip the value of a data
element on a text field rule in a Vuetify form.
The rule itself works fine, however I'm unable to access the data element, I'm getting this error:
TypeError: Cannot set property 'disabled' of undefined
Here is my code:
data: function() {
return {
disabled: false,
rules:{
sellerId(value){
if(value.length == 0){
this.disabled = true;
return "What are you trying to do here?";
}
else{
return true;
}
}
},
What am I doing wrong?
rules
are an array of functions, and if you need the function to be able to accessdata
property, you can define them as component methods:And then in your
Vuetify
component:While
this
isn't available to a rule function you can accomplish this by assigning the vue instance to a variable, which will bring it into scope by closure.try to define
rules
ascomputed
property :