Skip to content

Commit 3214ba2

Browse files
committed
validate video title length on client side
1 parent dfc1739 commit 3214ba2

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

app/components/dialogs/edit-video-dialog.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ export function EditVideoDialog() {
127127
<form.Field
128128
name="title"
129129
validators={{
130-
onChange: ({ value }) =>
131-
!value ? "A video title is required" : undefined,
130+
onChange: ({ value }) => {
131+
if (!value) return "A video title is required";
132+
if (value.length > 100)
133+
return "Title must be 100 characters or less";
134+
return undefined;
135+
},
132136
}}
133137
children={(field) => {
134138
return (
@@ -178,10 +182,7 @@ export function EditVideoDialog() {
178182
</Button>
179183
<Button
180184
className="grow basis-1/2 bg-blue-600 text-white"
181-
type="button"
182-
onMouseDown={() => {
183-
form.handleSubmit();
184-
}}
185+
type="submit"
185186
>
186187
Save Changes
187188
</Button>

app/components/dialogs/upload-video-dialog.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function UploadVideoDialogChild() {
8080
title.length--;
8181
}
8282

83-
return title.join(".");
83+
return title.join(".").substring(0, 99);
8484
}, []);
8585

8686
const form = useForm<FormData>({
@@ -150,6 +150,13 @@ function UploadVideoDialogChild() {
150150
>
151151
<form.Field
152152
name="title"
153+
validators={{
154+
onSubmit: ({ value }) => {
155+
if (value && value.length > 100)
156+
return "Title must be 100 characters or less";
157+
return undefined;
158+
},
159+
}}
153160
children={(field) => {
154161
return (
155162
<div>
@@ -163,6 +170,7 @@ function UploadVideoDialogChild() {
163170
placeholder="Enter video title (leave blank to use file name)"
164171
className="dark:bg-gray-800 border-gray-700 mt-1"
165172
/>
173+
<FieldInfo field={field} />
166174
</div>
167175
);
168176
}}

0 commit comments

Comments
 (0)