Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/createCharForm4 #20

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleAttributePerLine": false
}
37 changes: 29 additions & 8 deletions components/create-character/CChar-Form-1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,7 +78,8 @@ const races = [
];

const state = reactive({
name: undefined,
firstName: undefined,
lastName: undefined,
ruleset: "5e",
class: undefined,
alignment: undefined,
Expand All @@ -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;
};
Expand All @@ -105,7 +116,8 @@ function updateFormStore(fields: CharacterForm) {

async function onSubmit(event: FormSubmitEvent<CharacterForm>) {
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,
Expand All @@ -121,9 +133,18 @@ async function onSubmit(event: FormSubmitEvent<CharacterForm>) {

<template>
<UForm :validate="validate" :state="state" @submit.prevent="onSubmit">
<UFormGroup label="Character Name" name="name" class="mb-4">
<UFormGroup label="Character First Name" name="firstName" class="mb-4">
<UInput
v-model="state.name"
v-model="state.firstName"
placeholder="Must be less than 25 characters"
:disabled="disabled"
type="text"
required
/>
</UFormGroup>
<UFormGroup label="Character Last Name" name="lastName" class="mb-4">
<UInput
v-model="state.lastName"
placeholder="Must be less than 25 characters"
:disabled="disabled"
type="text"
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading