Skip to content
Snippets Groups Projects
Commit e70ad5d5 authored by Jens Christian Aanestad's avatar Jens Christian Aanestad
Browse files

refactor/Added validation display for login and sign up

parent 8ec05c51
No related branches found
No related tags found
1 merge request!9Feat/login
Pipeline #273800 failed
<script setup lang="ts"> <script setup lang="ts">
const emit = defineEmits(['inputChangeEvent']);
const props = defineProps({ const props = defineProps({
label: { label: {
type: String, type: String,
...@@ -16,19 +17,33 @@ const props = defineProps({ ...@@ -16,19 +17,33 @@ const props = defineProps({
inputId: { inputId: {
type: String, type: String,
required: true required: true
},
modelValue: {
type: String,
default: ""
},
isValid: {
type: Boolean,
default: false
} }
}); });
const onInputEvent = (event: any) => {
emit('inputChangeEvent', event.target.value)
}
</script> </script>
<template> <template>
<div> <div>
<label :for="inputId">{{ label }}</label> <label :for="inputId">{{ label }}</label>
<input :type="props.type" <input :value="props.modelValue"
@input="onInputEvent"
:type="props.type"
class="form-control" class="form-control"
:placeholder="props.placeholder" :placeholder="props.placeholder"
:id="inputId" required /> :id="inputId" required />
<div class="invalid-feedback">Invalid {{ label }}</div> <div v-if="props.isValid" class="invalid-feedback">Invalid {{ label }}</div>
<div class="valid-feedback">Correct {{ label }}</div> <div v-else class="valid-feedback">Valid {{ label }}</div>
</div> </div>
</template> </template>
......
<script setup lang="ts"> <script setup lang="ts">
import BaseInput from '@/components/InputFields/BaseInput.vue' import BaseInput from '@/components/InputFields/BaseInput.vue'
import Button1 from '@/components/Buttons/Button1.vue' import Button1 from '@/components/Buttons/Button1.vue'
import { ref } from 'vue'
const emailRef = ref()
const passwordRef = ref()
const formRef = ref()
const handleEmailInputEvent = (newValue: any) => {
emailRef.value = newValue
console.log(emailRef.value)
}
const handlePasswordInputEvent = (newValue: any) => {
passwordRef.value = newValue
}
const handleSubmit = () => { const handleSubmit = () => {
formRef.value.classList.add("was-validated")
alert("Expected to be logged in when backend are finished") // Todo remove this line alert("Expected to be logged in when backend are finished") // Todo remove this line
} }
</script> </script>
<template> <template>
<div class="container-fluid"> <div class="container-fluid">
<form id="loginForm" @submit.prevent="handleSubmit"> <form ref="formRef" id="loginForm" @submit.prevent="handleSubmit">
<BaseInput id="emailInput" <BaseInput :model-value="emailRef"
@input-change-event="handleEmailInputEvent"
id="emailInput"
input-id="email" input-id="email"
type="text" type="email"
label="Email" label="Email"
placeholder="Enter your email"/> placeholder="Enter your email"/>
<BaseInput id="passwordInput" <BaseInput :model-value="passwordRef"
@input-change-event="handlePasswordInputEvent"
id="passwordInput"
input-id="password" input-id="password"
type="password" type="password"
label="Password" label="Password"
placeholder="Enter password"/> placeholder="Enter password"/>
<button1 id="confirmButton" @click="handleSubmit" button-text="Login"></button1> <button1 id="confirmButton" type="submit" @click="handleSubmit" button-text="Login"></button1>
</form> </form>
</div> </div>
</template> </template>
......
<script setup lang="ts"> <script setup lang="ts">
import BaseInput from '@/components/InputFields/BaseInput.vue' import BaseInput from '@/components/InputFields/BaseInput.vue'
import Button1 from '@/components/Buttons/Button1.vue' import Button1 from '@/components/Buttons/Button1.vue'
import { ref } from 'vue'
const firstNameRef = ref('')
const surnameRef = ref('')
const emailRef = ref('')
const passwordRef = ref('')
const confirmPasswordRef = ref('')
const formRef = ref()
const handleFirstNameInputEvent = (newValue: any) => {
firstNameRef.value = newValue
console.log(firstNameRef.value)
}
const handleSurnameInputEvent = (newValue: any) => {
surnameRef.value = newValue
}
const handleEmailInputEvent = (newValue: any) => {
emailRef.value = newValue
}
const handlePasswordInputEvent = (newValue: any) => {
passwordRef.value = newValue
}
const handleConfirmPasswordInputEvent = (newValue: any) => {
confirmPasswordRef.value = newValue
}
const handleSubmit = () => { const handleSubmit = () => {
formRef.value.classList.add("was-validated")
alert("Expected to be transferred to initial configuration") // Todo remove this line alert("Expected to be transferred to initial configuration") // Todo remove this line
} }
...@@ -10,28 +40,43 @@ const handleSubmit = () => { ...@@ -10,28 +40,43 @@ const handleSubmit = () => {
<template> <template>
<div class="container"> <div class="container">
<form id="signUpForm" @submit.prevent="handleSubmit"> <form ref="formRef" id="signUpForm" @submit.prevent="handleSubmit">
<BaseInput id="firstNameInput" <BaseInput :model-value="firstNameRef.value"
@input-change-event="handleFirstNameInputEvent"
ref="firstNameRef"
id="firstNameInput"
input-id="first-name" input-id="first-name"
type="text" type="text"
label="First name" label="First name"
placeholder="Enter your first name"/> placeholder="Enter your first name"/>
<BaseInput id="surnameInput" <BaseInput :model-value="surnameRef.value"
@input-change-event="handleSurnameInputEvent"
ref="surnameRef"
id="surnameInput"
input-id="surname" input-id="surname"
type="text" type="text"
label="Surname" label="Surname"
placeholder="Enter your surname"/> placeholder="Enter your surname"/>
<BaseInput id="emailInput" <BaseInput :model-value="emailRef.value"
@input-change-event="handleEmailInputEvent"
ref="emailRef"
id="emailInput"
input-id="email" input-id="email"
type="text" type="email"
label="Email" label="Email"
placeholder="Enter your email"/> placeholder="Enter your email"/>
<BaseInput id="passwordInput" <BaseInput :model-value="passwordRef.value"
@input-change-event="handlePasswordInputEvent"
ref="passwordRef"
id="passwordInput"
input-id="password" input-id="password"
type="password" type="password"
label="Password" label="Password"
placeholder="Enter password"/> placeholder="Enter password"/>
<BaseInput id="confirmPasswordInput" <BaseInput :model-value="confirmPasswordRef.value"
@input-change-event="handleConfirmPasswordInputEvent"
ref="confirmPasswordRef"
id="confirmPasswordInput"
input-id="confirmPassword" input-id="confirmPassword"
type="password" type="password"
label="Confirm Password" label="Confirm Password"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment