I'm trying to validate the the value field in an object contains an email. There could be potentially many of these objects in an array. When I evaluate if it's $dirty it says Value is undefined. The validation is also not working at all. I've never validated an array of objects before as assuming I'm accessing the data in the array wrong but I'm not sure
Example Object: Value will contain the email I'm trying to validate
{
option: null,
Value: null,
Environment: null
}
Validations:
validations: {
defaultFields: {
$each: {
Value: { email }
}
},
}
Custom Error Function: This is whats throwing the error on the first If statement but the validation isn't working either way
computed: {
emailErrors() {
const errors = [];
if (!this.$v.defaultFields.$each.Value.$dirty) return errors;
!this.$v.defaultFields.$each.Value.email && errors.push('You must enter a valid email');
return errors;
}
}
This is an example of the loop and the field in the loop i'm trying to iterate over and validate what is typed in is a valid email.
<v-form>
<div v-for="(defaultField, defaultIndex) in defaultFields" v-bind:key="`${defaultIndex}-default`">
<v-text-field
@input="$v.defaultFields.$each[defaultIndex].Value.$touch()"
@blur="$v.defaultFields.$each[defaultIndex].Value.$touch()"
:error-messages="emailErrors(defaultIndex)"
id="value"
v-model="defaultField.Value"
label="Email Address"
type="email"
></v-text-field>
</div>
</v-form>