From 0840786b2eef1b19b2be312f047eb698b982ac26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?=
<80620802+burakboduroglu@users.noreply.github.com>
Date: Fri, 18 Sep 2026 12:01:32 +0300
Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8F=B7=EF=B8=8F=20field-level=20e?=
=?UTF-8?q?rrors=20for=20form=20inputs=20-=20Input=20and=20Textarea=20take?=
=?UTF-8?q?=20an=20error=20message:=20shown=20under=20the=20field,=20the?=
=?UTF-8?q?=20=20=20field=20marked=20aria-invalid=20and=20described=20by?=
=?UTF-8?q?=20it=20-=20the=20backend's=20error=20body=20is=20{error,=20cod?=
=?UTF-8?q?e}=20with=20no=20field=20name,=20so=20server=20=20=20failures?=
=?UTF-8?q?=20stay=20in=20the=20form=20alert;=20field=20errors=20come=20fr?=
=?UTF-8?q?om=20client=20checks=20-=20pilot:=20the=20new-class=20form=20ch?=
=?UTF-8?q?ecks=20its=20name=20itself=20(noValidate),=20so=20a=20=20=20bla?=
=?UTF-8?q?nk=20or=20spaces-only=20name=20is=20flagged=20in=20the=20app's?=
=?UTF-8?q?=20words=20and=20not=20sent=20-=20test=20for=20the=20class=20na?=
=?UTF-8?q?me=20check=20and=20its=20aria=20wiring?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/ui/input.tsx | 20 +++++++++++++++++---
src/components/ui/textarea.tsx | 22 ++++++++++++++++++----
src/i18n/messages.ts | 3 +++
src/pages/classes-page.test.tsx | 15 +++++++++++++++
src/pages/classes-page.tsx | 12 ++++++++++--
5 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx
index acab65c..a26f9d0 100644
--- a/src/components/ui/input.tsx
+++ b/src/components/ui/input.tsx
@@ -1,18 +1,32 @@
import type { ComponentProps } from "solid-js";
-import { splitProps } from "solid-js";
+import { Show, splitProps } from "solid-js";
import { cn } from "@/lib/cn";
-export type InputProps = ComponentProps<"input">;
+export type InputProps = ComponentProps<"input"> & {
+ /**
+ * Message shown under the field. Marks it invalid and describes it for
+ * assistive tech; needs an `id` so the message can be linked.
+ */
+ error?: string;
+};
export function Input(props: InputProps) {
- const [local, rest] = splitProps(props, ["class"]);
+ const [local, rest] = splitProps(props, ["class", "error"]);
+ const errorId = () => (props.id ? `${props.id}-error` : undefined);
return (
+ <>
+
+ {local.error}
+
+ >
);
}
diff --git a/src/components/ui/textarea.tsx b/src/components/ui/textarea.tsx
index bd4f700..355e7db 100644
--- a/src/components/ui/textarea.tsx
+++ b/src/components/ui/textarea.tsx
@@ -1,18 +1,32 @@
import type { ComponentProps } from "solid-js";
-import { splitProps } from "solid-js";
+import { Show, splitProps } from "solid-js";
import { cn } from "@/lib/cn";
-export type TextareaProps = ComponentProps<"textarea">;
+export type TextareaProps = ComponentProps<"textarea"> & {
+ /**
+ * Message shown under the field. Marks it invalid and describes it for
+ * assistive tech; needs an `id` so the message can be linked.
+ */
+ error?: string;
+};
export function Textarea(props: TextareaProps) {
- const [local, rest] = splitProps(props, ["class"]);
+ const [local, rest] = splitProps(props, ["class", "error"]);
+ const errorId = () => (props.id ? `${props.id}-error` : undefined);
return (
+ <>
+
+ {local.error}
+
+ >
);
}
diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts
index da2da1c..8fe18fd 100644
--- a/src/i18n/messages.ts
+++ b/src/i18n/messages.ts
@@ -616,6 +616,7 @@ export type MessageKey =
| "common.deleted"
| "common.saved"
| "common.loadAll"
+ | "form.fieldRequired"
| "common.close"
| "common.dismiss"
| "sidePanel.discardTitle"
@@ -2757,6 +2758,7 @@ const en: Dict = {
"common.deleted": "Deleted.",
"common.saved": "Saved successfully.",
"common.loadAll": "Load all",
+ "form.fieldRequired": "This field is required.",
"common.close": "Close",
"common.dismiss": "Dismiss",
"sidePanel.discardTitle": "Discard your changes?",
@@ -4900,6 +4902,7 @@ const tr: Dict = {
"common.deleted": "Silindi.",
"common.saved": "Başarıyla kaydedildi.",
"common.loadAll": "Tümünü yükle",
+ "form.fieldRequired": "Bu alan zorunlu.",
"common.close": "Kapat",
"common.dismiss": "Gizle",
"sidePanel.discardTitle": "Değişiklikler silinsin mi?",
diff --git a/src/pages/classes-page.test.tsx b/src/pages/classes-page.test.tsx
index 0e89f43..71c8471 100644
--- a/src/pages/classes-page.test.tsx
+++ b/src/pages/classes-page.test.tsx
@@ -86,3 +86,18 @@ test("a create whose blueprint left pairs behind holds the page until the report
expect(navigate).toHaveBeenCalledWith({ to: "/management/classes/$id", params: { id: "c-new" } }),
);
});
+
+test("a blank class name is flagged under the field, not sent", async () => {
+ getClasses.mockResolvedValue({ items: [] });
+ render(() => );
+
+ fireEvent.click(await screen.findByRole("button", { name: /New class/ }));
+ const field = await screen.findByLabelText(/^Name/);
+ fireEvent.input(field, { target: { value: " " } });
+ fireEvent.click(screen.getByRole("button", { name: "Create" }));
+
+ expect(await screen.findByText(/This field is required|Bu alan zorunlu/)).toBeTruthy();
+ expect(field.getAttribute("aria-invalid")).toBe("true");
+ expect(field.getAttribute("aria-describedby")).toBe("class-name-error");
+ expect(postClass).not.toHaveBeenCalled();
+});
diff --git a/src/pages/classes-page.tsx b/src/pages/classes-page.tsx
index 03401b8..898613c 100644
--- a/src/pages/classes-page.tsx
+++ b/src/pages/classes-page.tsx
@@ -57,6 +57,7 @@ function ClassesContent() {
const [yearId, setYearId] = createSignal("");
const [teacherId, setTeacherId] = createSignal("");
const [error, setError] = createSignal("");
+ const [nameError, setNameError] = createSignal("");
const [pending, setPending] = createSignal(false);
// A create whose grade's blueprint left pairs behind reports them here before
// it opens the class: the response is the only place those rows ever appear.
@@ -116,6 +117,13 @@ function ClassesContent() {
const createClass = async (event: SubmitEvent) => {
event.preventDefault();
setError("");
+ // Checked here rather than by the browser, so the message sits under the
+ // field in the app's own words — and a name of only spaces is caught too.
+ if (!name().trim()) {
+ setNameError(t("form.fieldRequired"));
+ document.getElementById("class-name")?.focus();
+ return;
+ }
setPending(true);
try {
const created = await postClass({
@@ -174,9 +182,9 @@ function ClassesContent() {
return (