Production Guides & Recipes
Managed Unicode Slugs
Section titled “Managed Unicode Slugs”The slugField factory generates clean, URL-friendly slugs while preserving non-Latin scripts (such as Persian and Arabic):
import { slugField } from "@nexload-sdk/payload-fields";
const fields = [ { name: "title", type: "text", required: true }, ...slugField({ source: "title", overrides: { slug: { admin: { position: "sidebar", description: "Auto-generated from title. Unlock to manually edit.", }, }, }, }),];Uniqueness & Collision Suffixing
Section titled “Uniqueness & Collision Suffixing”- Slugs are unique by default (
unique: true). When creating a document whose generated slug already exists, the factory automatically searches for non-colliding suffixes (-2,-3, up to-50). - Top-level only: Uniqueness collision queries apply only to top-level fields. Slugs placed inside nested arrays or groups receive character normalization only.
- If migrating an existing database with duplicate slug values, resolve duplicates before creating unique indexes or pass
unique: false.
Slug Locking Mechanism
Section titled “Slug Locking Mechanism”- When a document is created,
slugLockdefaults totrue. - Editing the source field updates
slugwhile locked. - Once locked documents are published, unlocking allows manual editing. While unlocked, source edits never change the slug. A locked slug follows source edits unless you pass
regenerateOnSourceChange: false.
Jalali (Persian Solar) Datepicker & Date Ranges
Section titled “Jalali (Persian Solar) Datepicker & Date Ranges”Store standard ISO datetimes while providing a rich Persian Solar calendar widget in Payload Admin:
import { jalaliDateField, jalaliDateRangeField, withJalaliTimestamps } from "@nexload-sdk/payload-fields";
const fields = [ jalaliDateField({ name: "eventDate", pickerAppearance: "dayAndTime", // Options: "dayOnly" | "dayAndTime" | "monthOnly" | "timeOnly" timeZone: "Asia/Tehran", // Default timezone }), jalaliDateRangeField({ start: "registrationStart", end: "registrationEnd", }),];
// Adds virtual read-only createdAtJalali and updatedAtJalali fieldsexport const collectionFields = withJalaliTimestamps(fields);Date Storage Guarantees
Section titled “Date Storage Guarantees”- The database always stores standard UTC ISO 8601 strings (e.g.
2026-07-24T08:30:00.000Z). - For
dayOnlyandmonthOnly, dates store canonical noon (12:00:00) intimeZone(defaultAsia/Tehran). This prevents date shifts when users view or edit entries from different browser timezones. - In
jalaliDateRangeField, the end field includes server-side validation ensuring that the end date falls on or after the start date.
Safe-Integer Money Fields
Section titled “Safe-Integer Money Fields”Prevent floating point inaccuracies by storing currency in integer minor units:
import { moneyField } from "@nexload-sdk/payload-fields";
const fields = [ moneyField({ name: "unitPrice", currency: "IRT", // Stored in Tomans minMinorUnits: 0, maxMinorUnits: 10_000_000_000, }), moneyField({ name: "rialPrice", currency: "IRR", // Stored in Rials displayCurrency: "IRT", // Displayed as Tomans in Admin UI and list cell }),];API Strings & Plugin Requirement
Section titled “API Strings & Plugin Requirement”- In the Admin UI, users type numbers with Persian or Latin digits and thousands grouping.
- In REST, GraphQL, and Local API calls, values are stored as integers.
- Critical Requirement:
payloadFieldsPlugin()is REQUIRED if money values are sent as strings through REST or Local API (e.g."۱۲۳٬۴۵۶"or"123456"). Payload’s core runsparseFloat()on number fields before field hooks run, which corrupts Persian digits. The plugin registers abeforeOperationhook that normalizes string values to safe integers before Payload processes them.
Iranian Contact & Identity Fields
Section titled “Iranian Contact & Identity Fields”Standardize phone numbers, national identification, postal codes, and banking fields:
import { bankCardField, iranLandlineField, iranMobileField, legalIdField, nationalCodeField, postalCodeField, shebaField,} from "@nexload-sdk/payload-fields";
const fields = [ // Mobile: normalized to national 09XXXXXXXXX or E.164 +989XXXXXXXXX iranMobileField({ name: "mobile", storage: "national" }), // Landline: normalized with province area code iranLandlineField({ name: "phone" }), // National Code: 10 digits with checksum validation nationalCodeField({ name: "nationalCode" }), // Legal Entity ID: 11 digits with checksum validation legalIdField({ name: "companyId" }), // Postal Code: 10 digits postalCodeField({ name: "postalCode" }), // Bank Card: 16 digits with Luhn algorithm validation bankCardField({ name: "cardNumber" }), // Sheba (IBAN): 26 characters (IR...) with ISO 7064 validation shebaField({ name: "sheba" }),];Validation & Localization
Section titled “Validation & Localization”- Values written through any API are normalized server-side in
beforeValidate(Persian digits converted, dashes/spaces removed). - Validation errors are localized: admin sessions in
fa(e.g.fa-IR) see Persian error messages; other languages see English error messages. - Admin list views automatically display formatted strings via
FormattedCell(e.g.۰۹۱۲ ۳۴۵ ۶۷۸۹,۶۰۳۷-۹۹۱۲-۳۴۵۶-۷۸۹۰).
Iranian Address Group
Section titled “Iranian Address Group”Use iranAddressField to create a structured address group:
import { iranAddressField } from "@nexload-sdk/payload-fields";
const fields = [ iranAddressField({ name: "shippingAddress", required: true, recipient: true, // Includes recipientName and recipientMobile fields }),];- Province selection contains all 31 Iranian provinces with localized Persian and English labels.
- Includes city, address line (textarea), and validated postal code.
Search Key Field
Section titled “Search Key Field”Use searchKeyField to maintain a hidden, read-only, indexed text field populated with toSearchIndexText from one or more source fields on create and update:
import { searchKeyField } from "@nexload-sdk/payload-fields";
const fields = [ { name: "title", type: "text", required: true }, searchKeyField({ name: "searchKey", sources: ["title"], localized: true, }),];Schema Adapter (@nexload-sdk/payload-fields/schema)
Section titled “Schema Adapter (@nexload-sdk/payload-fields/schema)”When using @nexload-sdk/payload-schema to share validation contracts with frontend forms or RPC endpoints:
import { defineEntity } from "@nexload-sdk/payload-schema";import { schemaFields } from "@nexload-sdk/payload-fields/schema";
export const customerEntity = defineEntity({ name: "Customer", fields: { mobile: schemaFields.iranMobile(), nationalCode: schemaFields.nationalCode(), price: schemaFields.money({ currency: "IRT" }), birthDate: schemaFields.jalaliDate({ nullable: true }), ...schemaFields.slug({ source: "title" }), },});Note:
iranAddressFieldandjalaliDateRangeFieldare not included in./schemain 4.0 because compound fields (groups and rows) require entity-level schema composition.
Troubleshooting & Common Pitfalls
Section titled “Troubleshooting & Common Pitfalls”1. Custom Admin Controls Fallback to Plain Inputs
Section titled “1. Custom Admin Controls Fallback to Plain Inputs”If Payload Admin displays plain number or text inputs instead of the Jalali datepicker or formatted money input:
- Regenerate Payload’s Import Map by running:
Terminal window pnpm payload generate:importmap - Ensure
@payloadcms/uiandpayloadare>=3.85.0 <4.0.0and React is^19.0.0.
2. Money Strings Rejected by REST or Local API
Section titled “2. Money Strings Rejected by REST or Local API”If sending string values like "150000" or "۱۵۰٬۰۰۰" fails validation or gets parsed as NaN:
- Ensure
payloadFieldsPlugin()is registered in yourpayload.config.tsplugins array. - The plugin interceptively normalizes string money values in
beforeOperationbefore Payload’s coreparseFloat()runs.
3. Duplicate Slug Migration Errors
Section titled “3. Duplicate Slug Migration Errors”If adding slugField to an existing collection throws a unique constraint database error:
- Deduplicate existing documents before deploying the schema change, or temporarily configure
slugField({ unique: false }).