I have a validated form:
<label class="form-label" for="full name">¿Cómo te llamas?</label>
<input class="form-control" placeholder="ej: María" type="text" v-model="name" required>
<div class="alert alert-danger w-100" v-if="msg.name">{{msg.name}}</div>
<label class="form-label" for="email">Email de empresa:</label>
<input class="form-control" placeholder="maria@lamejorempresadelmundo.com" type="text" v-model="email" required> <br>
<div class="alert alert-danger w-100" v-if="msg.email">{{msg.email}}</div>
<label class="form-label" type="password" for="password">Contraseña:</label>
<input class="form-control" type="text" v-model="password" required><br>
<div class="alert alert-danger w-100" v-if="msg.password">{{msg.password}}</div>
I want the submit button to show only if the 3 validation methods are met. I've tried to return true in each validation and make the submit have an v-if to check the 3 with no luck. Any ideas?
<button type="submit" @click.prevent="submit" v-if="this.validateEmail == true && this.validateName == true && this.validatePassword == true" >Finalizar</button>
For validations, I use 3 different methods that already work correctly:
Data
msg: [],
Watcher
watch: {
email(value){
this.email = value;
this.validateEmail(value);
},
password(value){
this.password = value;
this.validatePassword(value);
},
name(value){
this.name = value;
this.validateName(value);
}
}
Validation Methods
validateEmail(value){
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)) {
this.msg['email'] = ''
return false
} else {
this.msg['email'] = 'Email no válido';
return true
}
},
validatePassword(value){
let difference = 6 - value.length;
if (value.length<6) {
this.msg['password'] = 'Mínimo 6 caracteres - '+ difference + ' caracteres restantes' ;
return false
} else {
this.msg['password'] = '';
return true
}
},
validateName(value){
let difference = 4 - value.length;
if (value.length < 4) {
return false
this.msg['name'] = 'Mínimo 4 caracteres - '+ difference + ' caracteres restantes' ;
} else {
this.msg['name'] = '';
return true
}