Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/ninety-oranges-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"create-t3-app": patch
---

fix: prevent empty input submission in post creation form

- Disable submit button on frontend when input is empty
- Add `.trim()` validation on backend to reject empty/whitespace-only submissions
2 changes: 1 addition & 1 deletion cli/template/extras/src/app/_components/post-tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function LatestPost() {
<button
type="submit"
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20"
disabled={createPost.isPending}
disabled={createPost.isPending || name.length === 0}
>
{createPost.isPending ? "Submitting..." : "Submit"}
</button>
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/app/_components/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function LatestPost() {
<button
type="submit"
className={styles.submitButton}
disabled={createPost.isPending}
disabled={createPost.isPending || name.length === 0}
>
{createPost.isPending ? "Submitting..." : "Submit"}
</button>
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/api/routers/post/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ input }) => {
const post: Post = {
id: posts.length + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ ctx, input }) => {
await ctx.db.insert(posts).values({
name: input.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ ctx, input }) => {
return ctx.db.post.create({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ input }) => {
post = { id: post.id + 1, name: input.name };
return post;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ ctx, input }) => {
await ctx.db.insert(posts).values({
name: input.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ name: z.string().min(1) }))
.input(z.object({ name: z.string().trim().min(1) }))
.mutation(async ({ ctx, input }) => {
return ctx.db.post.create({
data: {
Expand Down