Skip to content

Commit

Permalink
Merge pull request #33 from CharlBest/limit-input-field-text-length
Browse files Browse the repository at this point in the history
Add max 50 character limit to text input fields
  • Loading branch information
scosman authored Mar 12, 2024
2 parents dcaa344 + 01e1244 commit 7de7216
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
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

0 comments on commit 7de7216

Please sign in to comment.