From efcee593a063a2b6e02aa6b21151068bcface117 Mon Sep 17 00:00:00 2001 From: Tom Slanda Date: Fri, 20 Sep 2024 15:30:49 -0400 Subject: [PATCH] added last name input (#20) Co-authored-by: Tom Slanda --- .prettierrc | 3 ++ components/create-character/CChar-Form-1.vue | 37 +++++++++++++++----- package-lock.json | 6 ++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.prettierrc b/.prettierrc index e69de29..6aa114f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleAttributePerLine": false + } \ No newline at end of file diff --git a/components/create-character/CChar-Form-1.vue b/components/create-character/CChar-Form-1.vue index a90f2d2..9a715be 100644 --- a/components/create-character/CChar-Form-1.vue +++ b/components/create-character/CChar-Form-1.vue @@ -5,7 +5,8 @@ import type { FormError, FormSubmitEvent } from "#ui/types"; import { useAuthStore, useFormStore } from "#imports"; type CharacterForm = { - name: string; + firstName: string; + lastName: string; ruleset: string; class: string; alignment: string; @@ -77,7 +78,8 @@ const races = [ ]; const state = reactive({ - name: undefined, + firstName: undefined, + lastName: undefined, ruleset: "5e", class: undefined, alignment: undefined, @@ -90,9 +92,18 @@ const buttonText = ref("Next Step: Appearance"); const validate = (state: CharacterForm): FormError[] => { const errors = []; - if (!state.name) errors.push({ path: "name", message: "Required" }); - if (state.name && state.name.length > 25) - errors.push({ path: "name", message: "Must be less than 25 characters" }); + if (!state.firstName) errors.push({ path: "firstName", message: "Required" }); + if (state.firstName && state.firstName.length > 25) + errors.push({ + path: "firstName", + message: "Must be less than 25 characters", + }); + if (!state.lastName) errors.push({ path: "lastName", message: "Required" }); + if (state.lastName && state.lastName.length > 25) + errors.push({ + path: "firstName", + message: "Must be less than 25 characters", + }); if (!state.alignment) errors.push({ path: "alignment", message: "Required" }); return errors; }; @@ -105,7 +116,8 @@ function updateFormStore(fields: CharacterForm) { async function onSubmit(event: FormSubmitEvent) { const eventData = { - name: event.data.name, + firstName: event.data.firstName, + lastName: event.data.lastName, ruleset: event.data.ruleset, class: event.data.class, alignment: event.data.alignment, @@ -121,9 +133,18 @@ async function onSubmit(event: FormSubmitEvent) {