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

Refactor/changed validation in SignUp (currently is gonna fail)

parent dfd056ec
No related branches found
No related tags found
1 merge request!24Refactor/changed validation in SignUp (currently is gonna fail)
Pipeline #275198 failed
<script setup lang="ts"> <script setup lang="ts">
import { RouterView } from 'vue-router' import { RouterView } from 'vue-router'
import ErrorBoundaryCatcher from '@/components/Exceptions/ErrorBoundaryCatcher.vue'; // import ErrorBoundaryCatcher from '@/components/Exceptions/ErrorBoundaryCatcher.vue';
</script> </script>
<template> <template>
......
...@@ -22,6 +22,7 @@ const onChangedChallengeEvent = (value) => { ...@@ -22,6 +22,7 @@ const onChangedChallengeEvent = (value) => {
console.log('Reached') console.log('Reached')
chosenChallenges.value = chosenChallenges.value.filter(item => item !== value[0]); chosenChallenges.value = chosenChallenges.value.filter(item => item !== value[0]);
} }
console.log(chosenChallenges.value)
} }
const onClick = () => { const onClick = () => {
......
...@@ -22,10 +22,6 @@ const props = defineProps({ ...@@ -22,10 +22,6 @@ const props = defineProps({
type: String, type: String,
default: "" default: ""
}, },
isValid: {
type: Boolean,
default: false
},
min: { min: {
type: String, type: String,
required: false required: false
...@@ -33,6 +29,14 @@ const props = defineProps({ ...@@ -33,6 +29,14 @@ const props = defineProps({
pattern: { pattern: {
type: String, type: String,
default: null default: null
},
validMessage: {
type: String,
default: ''
},
invalidMessage: {
type: String,
default: ''
} }
}); });
...@@ -44,17 +48,16 @@ const onInputEvent = (event: any) => { ...@@ -44,17 +48,16 @@ const onInputEvent = (event: any) => {
<template> <template>
<div> <div>
<label :for="inputId">{{ label }}</label> <label :for="inputId">{{ label }}</label>
<input :value="props.modelValue" <input :value="modelValue"
@input="onInputEvent" @input="onInputEvent"
:type="props.type" :type="type"
class="form-control" class="form-control"
:placeholder="props.placeholder" :placeholder="placeholder"
:id="inputId" required :id="inputId" required
:min="min" :min="min"
:pattern="pattern" :pattern="pattern"/>
/> <div class="valid-feedback">{{ validMessage }}</div>
<div v-if="props.isValid" class="invalid-feedback">Invalid {{ label }}</div> <div class="invalid-feedback">{{ invalidMessage }}</div>
<div v-else class="valid-feedback">Valid {{ label }}</div>
</div> </div>
</template> </template>
......
...@@ -8,8 +8,8 @@ import { useRouter, useRoute } from 'vue-router'; ...@@ -8,8 +8,8 @@ import { useRouter, useRoute } from 'vue-router';
import handleUnknownError from '@/components/Exceptions/unkownErrorHandler'; import handleUnknownError from '@/components/Exceptions/unkownErrorHandler';
import { useErrorStore } from '@/stores/ErrorStore'; import { useErrorStore } from '@/stores/ErrorStore';
const emailRef = ref() const emailRef = ref('')
const passwordRef = ref() const passwordRef = ref('')
const formRef = ref() const formRef = ref()
let errorMsg = ref(''); let errorMsg = ref('');
...@@ -19,13 +19,18 @@ const userStore = useUserInfoStore(); ...@@ -19,13 +19,18 @@ const userStore = useUserInfoStore();
const handleEmailInputEvent = (newValue: any) => { const handleEmailInputEvent = (newValue: any) => {
emailRef.value = newValue emailRef.value = newValue
console.log(emailRef.value)
} }
const handlePasswordInputEvent = (newValue: any) => { const handlePasswordInputEvent = (newValue: any) => {
passwordRef.value = newValue passwordRef.value = newValue
console.log(passwordRef.value)
} }
const handleSubmit = async () => { const handleSubmit = async () => {
console.log(emailRef.value)
console.log(passwordRef.value)
formRef.value.classList.add("was-validated") formRef.value.classList.add("was-validated")
const loginUserPayload: LoginRequest = { const loginUserPayload: LoginRequest = {
email: emailRef.value, email: emailRef.value,
...@@ -60,10 +65,30 @@ const handleSubmit = async () => { ...@@ -60,10 +65,30 @@ const handleSubmit = async () => {
<template> <template>
<div class="container-fluid"> <div class="container-fluid">
<form ref="formRef" id="loginForm" @submit.prevent="handleSubmit" novalidate> <form ref="formRef" id="loginForm" @submit.prevent="handleSubmit" novalidate>
<BaseInput :model-value="emailRef" @input-change-event="handleEmailInputEvent" id="emailInput" input-id="email"
type="email" label="Email" placeholder="Enter your email" /> <BaseInput :model-value="emailRef"
<BaseInput pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,16}" :model-value="passwordRef" @input-change-event="handlePasswordInputEvent" id="passwordInput" @input-change-event="handleEmailInputEvent"
input-id="password" type="password" label="Password" placeholder="Enter password" /> id="emailInput"
input-id="email"
type="email"
label="Email"
placeholder="Enter your email"
valid-message="Valid email"
invalid-message="Invalid email"
/>
<BaseInput :model-value="passwordRef"
@input-change-event="handlePasswordInputEvent"
id="passwordInput"
input-id="password"
type="password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,16}"
label="Password"
placeholder="Enter password"
valid-message="Valid password"
invalid-message="Password must be between 4 and 16 characters and contain one capital letter, small letter and a number"
/>
<p class="text-danger">{{ errorMsg }}</p> <p class="text-danger">{{ errorMsg }}</p>
<button1 id="confirmButton" type="submit" @click="handleSubmit" button-text="Login"></button1> <button1 id="confirmButton" type="submit" @click="handleSubmit" button-text="Login"></button1>
</form> </form>
......
...@@ -5,15 +5,18 @@ import { ref } from 'vue' ...@@ -5,15 +5,18 @@ import { ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const router = useRouter(); const router = useRouter();
const firstNameRef = ref('') const firstNameRef = ref('')
const surnameRef = ref('') const surnameRef = ref('')
const emailRef = ref('') const emailRef = ref('')
const passwordRef = ref('') const passwordRef = ref('')
const confirmPasswordRef = ref('') const confirmPasswordRef = ref('')
const formRef = ref() const formRef = ref()
let samePasswords = ref(true)
const handleFirstNameInputEvent = (newValue: any) => { const handleFirstNameInputEvent = (newValue: any) => {
firstNameRef.value = newValue firstNameRef.value = newValue
console.log(firstNameRef.value)
} }
const handleSurnameInputEvent = (newValue: any) => { const handleSurnameInputEvent = (newValue: any) => {
...@@ -26,21 +29,30 @@ const handleEmailInputEvent = (newValue: any) => { ...@@ -26,21 +29,30 @@ const handleEmailInputEvent = (newValue: any) => {
const handlePasswordInputEvent = (newValue: any) => { const handlePasswordInputEvent = (newValue: any) => {
passwordRef.value = newValue passwordRef.value = newValue
console.log(passwordRef.value)
} }
const handleConfirmPasswordInputEvent = (newValue: any) => { const handleConfirmPasswordInputEvent = (newValue: any) => {
confirmPasswordRef.value = newValue confirmPasswordRef.value = newValue
console.log(confirmPasswordRef.value)
} }
const handleSubmit = () => { const handleSubmit = async () => {
console.log(firstNameRef.value)
samePasswords.value = (passwordRef.value === confirmPasswordRef.value)
console.log(samePasswords.value)
const form = formRef.value; const form = formRef.value;
// Check if the form is valid // Check if the form is valid
if (form.checkValidity()) { if (form.checkValidity()) {
// Form is valid, submit the form or perform other actions // Form is valid, submit the form or perform other actions
console.log('Form is valid'); console.log('Form is valid');
} else {
console.log('Form is not valid');
} }
formRef.value.classList.add("was-validated") formRef.value.classList.add("was-validated")
} }
...@@ -49,46 +61,54 @@ const handleSubmit = () => { ...@@ -49,46 +61,54 @@ const handleSubmit = () => {
<template> <template>
<div class="container"> <div class="container">
<form ref="formRef" id="signUpForm" @submit.prevent="handleSubmit"> <form ref="formRef" id="signUpForm" @submit.prevent="handleSubmit">
<BaseInput :model-value="firstNameRef.value" <BaseInput :model-value="firstNameRef"
@input-change-event="handleFirstNameInputEvent" @input-change-event="handleFirstNameInputEvent"
ref="firstNameRef" ref="firstNameRef"
id="firstNameInput" 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 :model-value="surnameRef.value" invalid-message="Please enter your first name"/>
<BaseInput :model-value="surnameRef"
@input-change-event="handleSurnameInputEvent" @input-change-event="handleSurnameInputEvent"
ref="surnameRef" ref="surnameRef"
id="surnameInput" 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 :model-value="emailRef.value" invalid-message="Please enter your surname"/>
<BaseInput :model-value="emailRef"
@input-change-event="handleEmailInputEvent" @input-change-event="handleEmailInputEvent"
ref="emailRef" ref="emailRef"
id="emailInput" id="emailInput"
input-id="email" input-id="email"
type="email" type="email"
label="Email" label="Email"
placeholder="Enter your email"/> placeholder="Enter your email"
<BaseInput :model-value="passwordRef.value" invalid-message="Invalid email"/>
<BaseInput :model-value="passwordRef"
@input-change-event="handlePasswordInputEvent" @input-change-event="handlePasswordInputEvent"
ref="passwordRef" ref="passwordRef"
id="passwordInput" id="passwordInput"
input-id="password" input-id="password"
type="password" type="password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,16}"
label="Password" label="Password"
placeholder="Enter password"/> placeholder="Enter password"
<BaseInput :model-value="confirmPasswordRef.value" invalid-message="Password must be between 4 and 16 characters and contain one capital letter, small letter and a number"/>
<BaseInput :modelValue="confirmPasswordRef"
@input-change-event="handleConfirmPasswordInputEvent" @input-change-event="handleConfirmPasswordInputEvent"
ref="confirmPasswordRef" ref="confirmPasswordRef"
id="confirmPasswordInput" id="confirmPasswordInput"
input-id="confirmPassword" input-id="confirmPassword"
type="password" type="password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,16}"
label="Confirm Password" label="Confirm Password"
placeholder="Confirm password"/> placeholder="Confirm password"
invalid-message="Password must be between 4 and 16 characters and contain one capital letter, small letter and a number"/>
<p v-if="samePasswords" class="text-danger">The passwords are not identical</p>
<button1 id="confirmButton" @click="handleSubmit" button-text="Sign up"></button1> <button1 id="confirmButton" @click="handleSubmit" button-text="Sign up"></button1>
</form> </form>
</div> </div>
......
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