Last active
March 31, 2020 10:38
-
-
Save Serhansolo/d34256325d5b24235b3f86c4a755e300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="columns"> | |
<div class="column is-half is-offset-one-quarter"> | |
<div class="card"> | |
<div class="card-content"> | |
<div | |
v-if="validationErrors.length" | |
class="notification is-danger is-light" | |
> | |
<button @click="resetError()" class="delete"></button> | |
<div class="content"> | |
Please resolve the following error(s) before proceeding. | |
<ul style="margin-top:0.3em; margin-left: 1em"> | |
<li | |
v-for="(error, index) in validationErrors" | |
:key="`error-${index}`" | |
v-html="error" | |
/> | |
</ul> | |
</div> | |
</div> | |
<form> | |
<div class="field"> | |
<label class="label">E-mail</label> | |
<div class="control"> | |
<input | |
v-model="email" | |
class="input" | |
type="text" | |
autocomplete="email" | |
placeholder="[email protected]" | |
/> | |
</div> | |
</div> | |
<div class="field"> | |
<label class="label">Password</label> | |
<div class="control"> | |
<input | |
v-model="password" | |
class="input" | |
type="password" | |
autocomplete="current-password" | |
placeholder="Password" | |
/> | |
</div> | |
</div> | |
<div class="field"> | |
<p class="control"> | |
<button @click.prevent="validate()" class="button is-success"> | |
Login | |
</button> | |
</p> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
email: null, | |
password: null, | |
validationErrors: [] | |
}; | |
}, | |
methods: { | |
resetError() { | |
this.validationErrors = []; | |
}, | |
validate() { | |
// Clear the errors before we validate again | |
this.resetError(); | |
// email validation | |
if (!this.email) { | |
this.validationErrors.push("<strong>E-mail</strong> cannot be empty."); | |
} | |
if (/.+@.+/.test(this.email) != true) { | |
this.validationErrors.push("<strong>E-mail</strong> must be valid."); | |
} | |
// password validation | |
if (!this.password) { | |
this.validationErrors.push("<strong>Password</strong> cannot be empty"); | |
} | |
if (/.{6,}/.test(this.password) != true) { | |
this.validationErrors.push( | |
"<strong>Password</strong> must be at least 6 characters long" | |
); | |
} | |
// when valid then sign in | |
if (this.validationErrors.length <= 0) { | |
this.signIn(); | |
} | |
}, | |
signIn() { | |
// @TODO signIn logic will come here | |
console.log("sign in", this.email, this.password); | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment