vault backup: 2026-05-15 15:30:34
This commit is contained in:
parent
d8958d742f
commit
62efd61aa0
5 changed files with 140 additions and 2 deletions
2
.obsidian/plugins/hoarder-sync/data.json
vendored
2
.obsidian/plugins/hoarder-sync/data.json
vendored
|
|
@ -4,7 +4,7 @@
|
|||
"syncFolder": "Hoarder",
|
||||
"attachmentsFolder": "Hoarder/attachments",
|
||||
"syncIntervalMinutes": 60,
|
||||
"lastSyncTimestamp": 1778851793772,
|
||||
"lastSyncTimestamp": 1778855393935,
|
||||
"updateExistingFiles": false,
|
||||
"excludeArchived": true,
|
||||
"onlyFavorites": false,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ This 3-hop pattern works for hundreds of articles without vector search.
|
|||
| [[wiki/reports/_index\|reports/]] | Weekly and monthly summaries — generate: `uv run python scripts/report-generator.py --weekly` | 1 |
|
||||
| [[wiki/infrastructure/_index\|infrastructure/]] | Server inventory: all 10 SSH hosts — optical, optical-dev, optical-prod, baic, librechat, modocmms, box-cli, aimpress, pve | 12 |
|
||||
| [[wiki/testing/_index\|testing/]] | Web app testing: functional, performance, security, UI types; TDD/BDD/Agile methodologies; Selenium/Cypress/Playwright/JMeter/OWASP ZAP tools | 1 |
|
||||
| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, ecommerce, production deploy, TypeScript, migration guides, i18n, localization | 72 |
|
||||
| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, ecommerce, production deploy, TypeScript, migration guides, i18n, localization | 73 |
|
||||
|
||||
| [[wiki/shared-patterns/_index\|shared-patterns/]] | Oliver Agency standard library patterns: httpx, structlog, pydantic-settings, alembic — reuse before writing from scratch | 4 |
|
||||
| [[wiki/mistakes/_index\|mistakes/]] | Anti-patterns extracted from sessions — per-stack running lists (fastapi, react, docker, postgres, general) — injected at session start | 5 |
|
||||
|
|
|
|||
|
|
@ -73,3 +73,4 @@
|
|||
| [[wiki/payloadcms/fields-group\|Group Field]] | Nest fields under a shared property (named) or visually group without nesting (presentational); `localized` covers all nested fields at once | raw/fields__group.md | 2026-05-15 |
|
||||
| [[wiki/payloadcms/fields-join\|Join Field]] | Virtual bi-directional relationship field — zero-overhead reverse lookup, custom junction tables, polymorphic, query options across all APIs | raw/fields__join.md | 2026-05-15 |
|
||||
| [[wiki/payloadcms/fields-json\|JSON Field]] | Stores native JSON in DB (not string) — jsonSchema validation + Monaco typeahead, local/remote schemas, vs Code Field | raw/fields__json.md | 2026-05-15 |
|
||||
| [[wiki/payloadcms/fields-number\|Number Field]] | Numeric field — min/max validation, hasMany array mode, step admin control, unique/index, virtual, custom components | raw/fields__number.md | 2026-05-15 |
|
||||
|
|
|
|||
137
wiki/payloadcms/fields-number.md
Normal file
137
wiki/payloadcms/fields-number.md
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
title: "Number Field"
|
||||
aliases: [payload-number-field, number-field-payloadcms]
|
||||
tags: [payloadcms, fields, number, validation]
|
||||
sources: [raw/fields__number.md]
|
||||
created: 2026-05-15
|
||||
updated: 2026-05-15
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
The Number Field stores and validates numeric values. It supports min/max validation, array mode (`hasMany`), and browser-level step controls.
|
||||
|
||||
```ts
|
||||
import type { Field } from 'payload'
|
||||
|
||||
export const MyNumberField: Field = {
|
||||
name: 'age',
|
||||
type: 'number',
|
||||
}
|
||||
```
|
||||
|
||||
## Config Options
|
||||
|
||||
| Option | Description |
|
||||
|--------|-------------|
|
||||
| `name` * | Property name in DB |
|
||||
| `min` | Minimum accepted value (used in default validation) |
|
||||
| `max` | Maximum accepted value (used in default validation) |
|
||||
| `hasMany` | Makes field an **ordered array** of numbers instead of a single number |
|
||||
| `minRows` | Min array length (requires `hasMany: true`) |
|
||||
| `maxRows` | Max array length (requires `hasMany: true`) |
|
||||
| `unique` | DB-level unique index on this field's path |
|
||||
| `index` | Build DB index for faster queries |
|
||||
| `validate` | Custom validation function (runs on both Admin Panel and backend) |
|
||||
| `saveToJWT` | Include field value in user JWT (top-level auth collections) |
|
||||
| `hooks` | Field lifecycle hooks |
|
||||
| `access` | Field-level access control |
|
||||
| `hidden` | Hidden from all APIs (still saved to DB) |
|
||||
| `defaultValue` | Default value |
|
||||
| `localized` | Enable per-locale values (requires localization in base config) |
|
||||
| `required` | Field must have a value |
|
||||
| `virtual` | `true` = no DB column; or a string path to link with a relationship |
|
||||
| `typescriptSchema` | Override TS type generation with JSON schema |
|
||||
| `custom` | Extension point for plugins |
|
||||
|
||||
## Admin Options
|
||||
|
||||
```ts
|
||||
admin: {
|
||||
step: 1, // increment/decrement step for browser controls
|
||||
placeholder: '0', // placeholder string
|
||||
autoComplete: 'age', // browser autocomplete hint
|
||||
}
|
||||
```
|
||||
|
||||
## hasMany — Array of Numbers
|
||||
|
||||
```ts
|
||||
{
|
||||
name: 'scores',
|
||||
type: 'number',
|
||||
hasMany: true,
|
||||
minRows: 1,
|
||||
maxRows: 10,
|
||||
}
|
||||
```
|
||||
|
||||
Stores an ordered array of numbers. Each element is still validated against `min`/`max` if provided.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import type { CollectionConfig } from 'payload'
|
||||
|
||||
export const ExampleCollection: CollectionConfig = {
|
||||
slug: 'example-collection',
|
||||
fields: [
|
||||
{
|
||||
name: 'age',
|
||||
type: 'number',
|
||||
required: true,
|
||||
min: 0,
|
||||
max: 150,
|
||||
admin: {
|
||||
step: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
## Custom Components
|
||||
|
||||
Import `NumberField` and `FieldLabel` from `@payloadcms/ui`.
|
||||
|
||||
**Server Component:**
|
||||
```tsx
|
||||
import { NumberField } from '@payloadcms/ui'
|
||||
import type { NumberFieldServerComponent } from 'payload'
|
||||
|
||||
export const CustomNumberFieldServer: NumberFieldServerComponent = ({
|
||||
clientField, path, schemaPath, permissions,
|
||||
}) => <NumberField field={clientField} path={path} schemaPath={schemaPath} permissions={permissions} />
|
||||
```
|
||||
|
||||
**Client Component:**
|
||||
```tsx
|
||||
'use client'
|
||||
import { NumberField } from '@payloadcms/ui'
|
||||
import type { NumberFieldClientComponent } from 'payload'
|
||||
|
||||
export const CustomNumberFieldClient: NumberFieldClientComponent = (props) => <NumberField {...props} />
|
||||
```
|
||||
|
||||
Label components follow the same server/client pattern using `FieldLabel`.
|
||||
|
||||
## Key Takeaways
|
||||
|
||||
- Use `min`/`max` for built-in range validation without writing a custom `validate` function.
|
||||
- `hasMany: true` turns the field into an ordered number array — pair with `minRows`/`maxRows` for length constraints.
|
||||
- `admin.step` controls the browser spinner increment; useful for integer fields (`step: 1`).
|
||||
- `unique` creates a DB-level index — avoid on arrays (`hasMany`) as uniqueness semantics are complex.
|
||||
- `virtual: true` skips DB storage entirely; use for computed/derived numeric values.
|
||||
|
||||
## Related
|
||||
|
||||
- [[wiki/payloadcms/fields-basic|Fields: Basic]] — all scalar field types overview
|
||||
- [[wiki/payloadcms/fields-email|Email Field]] — similar scalar field with format validation
|
||||
- [[wiki/payloadcms/fields-checkbox|Checkbox Field]] — another simple scalar field
|
||||
- [[wiki/payloadcms/database-indexes|Database Indexes]] — how `index: true` and `unique` work at DB level
|
||||
- [[wiki/payloadcms/authentication-token-data|Token Data (saveToJWT)]] — embedding field values in JWT
|
||||
|
||||
## Sources
|
||||
|
||||
- `raw/fields__number.md`
|
||||
- https://payloadcms.com/docs/fields/number
|
||||
Loading…
Add table
Reference in a new issue