อ้างอิง › Fields
เอกสาร/อ้างอิง/Fields

อ้างอิง field

ตัวเลือกทั้งหมดของ field มีเทสต์ตรวจกับ type ใน @easy-cms/core หน้าตาในหน้า admin และวิธีจัดเก็บดูได้ที่ Fields

ตัวเลือกของทุก field

ตัวเลือกType
namestringจำเป็น เป็นชื่อตัวแปรของ JavaScript และไม่ซ้ำกับ field ข้างเคียง
typeดูประเภทจำเป็น
labelstring | { en, th }ค่าเริ่มต้นคือชื่อ field ที่แปลงให้อ่านง่าย
requiredbooleanต้องมีค่า (ไม่ตรวจตอนบันทึกฉบับร่าง)
uniquebooleanเอกสารสองรายการใช้ค่าซ้ำกันไม่ได้ (field ระดับบนสุด)
uniqueWithinstring | string[]ใช้กับ unique หรือ slug: field ข้างเคียง (เช่น parent, tenant) ค่าห้ามซ้ำเฉพาะเอกสารที่มีค่าใน field เหล่านั้นเหมือนกัน
indexbooleanสร้าง index ในฐานข้อมูล
defaultValueค่าของ fieldใช้เมื่อสร้างเอกสารโดยไม่มีค่านี้
validate(value, { data, operation }) => true | stringตรวจเอง เป็น async ได้
access{ read?, update? }สิทธิ์ระดับ field
hiddenbooleanถูกจัดเก็บ แต่ไม่ถูกส่งคืนและไม่รับเป็น input
localizedbooleanเก็บค่าแยกตามภาษา (ต้องมี localization)
position'sidebar'แสดงในแถบข้างของหน้าแก้ไข (field ระดับบนสุด)
adminFieldAdminadmin components ดูด้านล่าง
customTypestringEasy CMS ตั้งให้เองกับ field ของชนิดที่เพิ่มเข้ามา (เช่น color) ไม่ต้องตั้งเอง

admin

ตัวเลือกType
componentAdminComponentWeb Component แทนช่องกรอก Admin components
afterAdminComponent[]component ที่แสดงใต้ field
cellAdminComponentแสดงค่าในคอลัมน์ของหน้ารายการ เช่น จุดสี
descriptionLabelคำอธิบายใต้ field
width'1/4' | '1/3' | '1/2' | '2/3' | '3/4' | 'full'สัดส่วนในแถว (admin.layout) ค่าเริ่มต้น: แบ่งเท่ากัน
conditionFieldConditionแสดงเฉพาะเมื่อ field ข้างเคียงตรงเงื่อนไข เช่น { field: 'linkType', equals: 'external' } มี notEquals, in, exists, and, or, not ด้วย field ที่ถูกซ่อนไม่ถูกบังคับกรอก ระบบจัดการ
columnboolean | ({ user, context }) => booleanแสดงเป็นคอลัมน์ของหน้ารายการตั้งแต่แรก (ผู้ใช้เปลี่ยนเองได้)
allowCreatebooleanrelationship: ให้สร้างเอกสารที่เชื่อมได้ทันที ค่าเริ่มต้น true
defaultValue({ user, context }) => unknownค่าเริ่มต้นของฟอร์มเอกสารใหม่ต่อผู้ใช้ เช่น จาก context ของ request

AdminComponent คือชื่อ tag ที่ขึ้นต้นด้วย ecms- หรือ { tag, props }

ประเภท

ประเภทค่าตัวเลือกเพิ่มเติม
textstringminLength, maxLength
textareastringminLength, maxLength
emailstring (ตัวพิมพ์เล็ก)
numbernumbermin, max
booleanboolean
datestring แบบ ISO 8601
selectหนึ่งตัวเลือก หรือ array เมื่อใช้ hasManyoptions, hasMany
slugstring ที่ปลอดภัยสำหรับ URL และไม่ซ้ำfrom
jsonJSON ใดก็ได้
richTextJSON ของ Tiptapดู Rich text
uploadid ของเอกสาร media หรือ array เมื่อใช้ hasManyhasMany, mimeTypes
relationshipid ของเอกสารto, hasMany
arrayแถวที่มี id และ field ย่อยfields, minRows, maxRows
groupobjectfields
blocksแถวหลายชนิด มี blockTypeblocks, minRows, maxRows

แพ็กเกจเพิ่มชนิดอื่นได้ เช่น color จาก @easy-cms/fields ดูชนิด field เพิ่มเติม

text และ textarea

ตัวเลือกType
minLengthnumberจำนวนตัวอักษรน้อยที่สุด
maxLengthnumberจำนวนตัวอักษรมากที่สุด หน้า admin จะพิมพ์เกินไม่ได้

number

ตัวเลือกType
minnumberค่าน้อยที่สุด
maxnumberค่ามากที่สุด

select

ตัวเลือกType
options(string | { label, value })[]จำเป็น ตัวเลือก label เป็น { en, th } ได้
hasManybooleanเลือกได้หลายตัว (checkbox) ค่าเป็น array

slug

ตัวเลือกType
fromstringfield แบบ text ข้างเคียงที่ใช้สร้าง slug เมื่อยังว่าง
uniqueWithinstringfield ข้างเคียง (เช่น parent): slug ห้ามซ้ำเฉพาะเอกสารที่มีค่าใน field นั้นเหมือนกัน

upload

ตัวเลือกType
hasManybooleanหลายไฟล์ เรียงตามที่ผู้แก้จัดไว้ (แกลเลอรี) ค่าเป็น array
minRowsnumberเมื่อใช้ hasMany: จำนวนไฟล์ขั้นต่ำ
maxRowsnumberเมื่อใช้ hasMany: จำนวนไฟล์สูงสุด
mimeTypesstring[]ชนิดไฟล์ที่อนุญาต เช่น ['image/*'] ช่องเลือกแสดงเฉพาะชนิดนี้ และตรวจซ้ำตอนบันทึก

relationship

ตัวเลือกType
tostringจำเป็น slug ของ collection ปลายทาง
hasManybooleanหลายเอกสาร ค่าเป็น array
minRowsnumberเมื่อใช้ hasMany: จำนวนเอกสารขั้นต่ำ
maxRowsnumberเมื่อใช้ hasMany: จำนวนเอกสารสูงสุด
filterOptions({ id, user, cms }) => Where | trueเอกสารใดที่เลือกได้ ช่องเลือกใน admin แสดงเฉพาะเอกสารเหล่านี้ และตรวจซ้ำตอนบันทึก

array

ตัวเลือกType
fieldsField[]จำเป็น field ของแต่ละแถว
minRowsnumberจำนวนแถวน้อยที่สุด
maxRowsnumberจำนวนแถวมากที่สุด

group

ตัวเลือกType
fieldsField[]จำเป็น field ข้างใน

blocks

ตัวเลือกType
blocksBlock[]จำเป็น ชนิดของแถว ดู Block
minRowsnumberจำนวนแถวน้อยที่สุด
maxRowsnumberจำนวนแถวมากที่สุด

Block

ตัวเลือกType
slugstringจำเป็น เก็บในแต่ละแถวเป็น blockType
labels{ singular?, plural? }ชื่อในหน้า admin
fieldsField[]จำเป็น field ของ block