feat: Implement initial e-learning platform frontend structure including dashboard, course management, authentication, and common UI components.
This commit is contained in:
parent
aceeb80d9a
commit
ad11c6b7c5
44 changed files with 720 additions and 578 deletions
|
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* @interface ValidationRule
|
||||
* @description กฎการตรวจสอบความถูกต้องของฟิลด์ (เช่น บังคับกรอก, เช็คความยาว, ตรวจอีเมล)
|
||||
*/
|
||||
export interface ValidationRule {
|
||||
required?: boolean
|
||||
minLength?: number
|
||||
|
|
@ -8,10 +12,18 @@ export interface ValidationRule {
|
|||
custom?: (value: string) => string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface FieldErrors
|
||||
* @description รูปแบบการเก็บข้อผิดพลาด (Key ของฟิลด์ คู่กับข้อความแจ้งเตือน)
|
||||
*/
|
||||
export interface FieldErrors {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @composable useFormValidation
|
||||
* @description ใช้สำหรับตรวจสอบความถูกต้อง (Validate) ของข้อมูลในแบบฟอร์ม
|
||||
*/
|
||||
export function useFormValidation() {
|
||||
const errors = ref<FieldErrors>({})
|
||||
|
||||
|
|
@ -52,6 +64,7 @@ export function useFormValidation() {
|
|||
return null
|
||||
}
|
||||
|
||||
// ฟังก์ชันหลักที่เอาแบบฟอร์ม (formData) มาตรวจกับเช็คลิสต์ทั้งหมด (validationRules)
|
||||
const validate = (
|
||||
formData: Record<string, string>,
|
||||
validationRules: Record<string, { rules: ValidationRule; label: string; messages?: Record<string, string> }>
|
||||
|
|
@ -67,14 +80,18 @@ export function useFormValidation() {
|
|||
}
|
||||
}
|
||||
|
||||
// บันทึกข้อผิดพลาดที่พบทั้งหมดลงใน State
|
||||
errors.value = newErrors
|
||||
// คืนค่าบอกว่า "ฟอร์มนี้ผ่านทั้งหมดไหม" (true คือผ่านหมด)
|
||||
return isValid
|
||||
}
|
||||
|
||||
// ฟังก์ชันลบข้อผิดพลาดทิ้งทั้งหมด (สำหรับตอนเริ่มกรอกใหม่)
|
||||
const clearErrors = () => {
|
||||
errors.value = {}
|
||||
}
|
||||
|
||||
// ฟังก์ชันลบข้อผิดพลาดเฉพาะฟิลด์ที่กำหนด
|
||||
const clearFieldError = (field: string) => {
|
||||
if (errors.value[field]) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue