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

Input limit staging #42

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@
label: "Name",
initialValue: profile?.full_name ?? "",
placeholder: "Your full name",
maxlength: 50,
},
{
id: "companyName",
label: "Company Name",
initialValue: profile?.company_name ?? "",
maxlength: 50,
},
{
id: "website",
label: "Company Website",
initialValue: profile?.website ?? "",
maxlength: 50,
},
]}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
label?: string
initialValue: string | boolean
placeholder?: string
maxlength?: number
}

// Module context
Expand Down Expand Up @@ -96,6 +97,7 @@
? 'input-error'
: ''} input-sm mt-1 input input-bordered w-full max-w-xs mb-3 text-base py-4"
value={$page.form ? $page.form[field.id] : field.initialValue}
maxlength={field.maxlength ? `${field.maxlength}` : null}
/>
{:else}
<div class="text-lg mb-3">{field.initialValue}</div>
Expand Down
10 changes: 10 additions & 0 deletions src/routes/(admin)/account/api/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,30 @@ export const actions = {
const website = formData.get("website") as string

let validationError
const fieldMaxTextLength = 50
const errorFields = []
if (!fullName) {
validationError = "Name is required"
errorFields.push("fullName")
} else if (fullName.length > fieldMaxTextLength) {
validationError = `Name must be less than ${fieldMaxTextLength} characters`
errorFields.push("fullName")
}
if (!companyName) {
validationError =
"Company name is required. If this is a hobby project or personal app, please put your name."
errorFields.push("companyName")
} else if (companyName.length > fieldMaxTextLength) {
validationError = `Company name must be less than ${fieldMaxTextLength} characters`
errorFields.push("companyName")
}
if (!website) {
validationError =
"Company website is required. An app store URL is a good alternative if you don't have a website."
errorFields.push("website")
} else if (website.length > fieldMaxTextLength) {
validationError = `Company website must be less than ${fieldMaxTextLength} characters`
errorFields.push("website")
}
if (validationError) {
return fail(400, {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/(admin)/account/create_profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
? 'input-error'
: ''} mt-1 input input-bordered w-full max-w-xs"
value={form?.fullName ?? fullName}
maxlength="50"
/>
</div>

Expand All @@ -73,6 +74,7 @@
? 'input-error'
: ''} mt-1 input input-bordered w-full max-w-xs"
value={form?.companyName ?? companyName}
maxlength="50"
/>
</div>

Expand All @@ -89,6 +91,7 @@
? 'input-error'
: ''} mt-1 input input-bordered w-full max-w-xs"
value={form?.website ?? website}
maxlength="50"
/>
</div>

Expand Down
Loading