# Training Type Review

## Root Cause

- The form uses TanStack Form, not React Hook Form.
- `trainingType` in create mode was initialized as `undefined`.
- The field-level blur validator had already been improved, but the submit-level Zod schema still used `z.enum(...)`.
- When submit validation ran with an unset value, Zod could still produce a raw type error path like `expected string, received undefined` instead of the intended Thai message.

## Files Changed

- `src/features/training-records/schemas/training-record.ts`
- `src/features/training-records/components/training-record-form.tsx`

## Fixed Code Summary

- Changed `trainingType` form default from `undefined` to `""` in create mode.
- Kept edit mode bound to the stored UI value.
- Updated the `Select` binding to pass `undefined` to Radix only for display when the current form value is empty.
- Replaced submit-level `z.enum(...)` validation with string-based validation plus whitelist refinement so the message always stays:
  - `กรุณาเลือกประเภทการอบรม`
- Kept the current app enum contract intact:
  - `INTERNAL_TRAINING`
  - `EXTERNAL_TRAINING`
  - `ONLINE_COURSE`
  - `OJT`

## Regression Checklist

- Create mode: open new training record form and submit without selecting training type.
- Create mode: select each training type option and verify no raw Zod error appears.
- Edit mode: open an existing record and confirm the saved type renders correctly in the select.
- Edit mode: change the type and submit successfully.
- Validation after submit: confirm the Thai message appears instead of `Invalid input` or `expected string, received undefined`.
- Table/listing: verify training type badges still render correctly in Training Records and review pages.
- Server normalization: verify create/update payloads still map correctly to legacy DB values.
