-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45418b9
commit 7ef1859
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<template> | ||
<main> | ||
<Form | ||
:error="error" | ||
:schema="SCHEMA" | ||
Check failure on line 5 in src/demo/pages/SignupFormDemo.vue GitHub Actions / build
Check failure on line 5 in src/demo/pages/SignupFormDemo.vue GitHub Actions / lint
|
||
:reset-on="reset" | ||
@submit="onSubmit" | ||
@change="handleChangeOnError" | ||
> | ||
<Button type="submit">Submit</Button> | ||
</Form> | ||
</main> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Button, Form } from '../../components'; | ||
import { ref } from 'vue'; | ||
// Constants | ||
const SCHEMA = [ | ||
{ | ||
'data-test': 'email', | ||
id: 'email', | ||
name: 'email', | ||
label: 'Email', | ||
type: 'text', | ||
placeholder: 'Your email address', | ||
value: '', | ||
validators: { | ||
email: { | ||
message: 'Please provide your email address', | ||
value: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
'data-test': 'password', | ||
id: 'password', | ||
name: 'password', | ||
label: 'Password', | ||
type: 'password', | ||
placeholder: 'Your password', | ||
value: '', | ||
validators: { | ||
password: { | ||
message: 'Please provide your password', | ||
value: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
'data-test': 'confirm-password', | ||
id: 'confirmPassword', | ||
name: 'confirmPassword', | ||
label: 'Confirm Password', | ||
type: 'password', | ||
placeholder: 'Confirm your password', | ||
value: '', | ||
validators: { | ||
password: { | ||
message: 'Please confirm your password', | ||
value: true, | ||
}, | ||
}, | ||
}, | ||
]; | ||
const error = ref(undefined); | ||
const reset = ref(false); | ||
/** | ||
* When signing up: handles clearing pw-match form errors on change if they exist | ||
*/ | ||
function handleChangeOnError(formValues) { | ||
Check failure on line 74 in src/demo/pages/SignupFormDemo.vue GitHub Actions / build
|
||
console.debug('onchange', { e: error.value, formValues: formValues.value }); | ||
if (error.value && formValues.password !== formValues.confirmPassword) { | ||
handlePasswordValidation(formValues); | ||
} | ||
} | ||
/** | ||
* When signing up: validates that passwords match | ||
* @returns {boolean} `false` if passwords do not match, `true` if they do | ||
*/ | ||
function handlePasswordValidation(formValues) { | ||
Check failure on line 86 in src/demo/pages/SignupFormDemo.vue GitHub Actions / build
|
||
console.debug('validate', { e: error.value }); | ||
if (formValues.password !== formValues.confirmPassword) { | ||
if (!error.value) { | ||
error.value = 'Passwords do not match, please try again.'; | ||
Check failure on line 91 in src/demo/pages/SignupFormDemo.vue GitHub Actions / build
|
||
} | ||
return false; | ||
} else { | ||
error.value = undefined; | ||
return true; | ||
} | ||
} | ||
/** | ||
* Logs user in or signs user up | ||
*/ | ||
function onSubmit(formValues) { | ||
Check failure on line 103 in src/demo/pages/SignupFormDemo.vue GitHub Actions / build
|
||
console.debug('onsubmit', { e: error.value }); | ||
if (!handlePasswordValidation(formValues)) { | ||
return; | ||
} else { | ||
reset.value = true; | ||
} | ||
console.debug({ formValues }); | ||
} | ||
</script> |
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