Field Editor

Create or change a field: its name, kind, choices and colors, number format, link or formula.

  • StatusSelect
  • PrioritySelect
  • AssigneePerson
  • LabelsMulti-select
  • EstimateNumber
  • DueDate
  • CustomerRelation
  • ImpactRating

Edit Status

Changes apply to every view of this collection.

Type

Choices

Enter adds the next choice. Drag ⠿ or press Alt+↑ ↓ to reorder.

TodoIn ProgressIn ReviewDone

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/field-editor

Usage

import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { Property } from "./ui/uicontext/components/domain/Record.ts"import { FieldEditor } from "./ui/uicontext/components/kit/FieldEditor.ts"
const Message = UiSchema.TaggedEnum({	RequestedSaveField: { request: Schema.String, field: Property },	ClosedFieldEditor: {},})// `editing` is the field being changed, or null for a new one; `open` shows the dialog.export const EditField = (	h: Html.H<typeof Message.Type>,	open: boolean,	editing: Property | null,	fields: ReadonlyArray<Property>,	outcome: Outcome | null,) =>	FieldEditor(h, {		props: { open, field: editing, fields, outcome },		onEmit: {			// save the field, then answer with { _tag: "Accepted", request } as `outcome`			RequestedSaveField: (save) => Message.RequestedSaveField(save),			RequestedDeleteField: () => undefined,			RequestedClose: () => Message.ClosedFieldEditor(),		},	})

Examples

A refused change

Open Status and press Delete field: the app refuses, and the editor says why.

Choices and their colors

Reorder, recolor, add and remove a select's choices. Removing one, or changing the kind, warns what happens to existing values.

Edit Stage

Changes apply to every view of this collection.

Type

Choices

Enter adds the next choice. Drag ⠿ or press Alt+↑ ↓ to reorder.

LeadQualifiedProposalWonLost

API reference

Props

FieldEditor props
NameTypeDefaultDescription
openrequiredboolean—Whether the editor is showing; closing it comes back as RequestedClose
fieldrequiredProperty | null—The field to change; null makes a new one
fieldsrequiredProperty[]—Every field of the collection: names must differ, and rollups and formulas refer to them
targetsFieldTarget[]—What a relation can link to
outcomeOutcome | null—The app's answer to the latest save or delete request
canCan(["delete"])—"delete" offers Delete field when editing
localestring—The locale numbers and dates are formatted in; the browser's by default
agentIdstringfield-editorThis editor's id for agents, unique on the page; field-editor by default
inlineboolean—Draw the editor in place, as a panel in the page, instead of in a dialog: for a settings page or a side panel. open still decides whether it shows.

Events

FieldEditor events
EventPayloadDescription
RequestedSaveField{ request: string; field: Property }Save this field (a new one when its key is new); answer through outcome with the same request
RequestedDeleteField{ request: string; key: string }Delete the field; answer through outcome with the same request
RequestedClose{}Close the editor: cancelled, dismissed, or the app accepted the change

Agent actions

What agents can do with FieldEditor
ActionDescription
ProposedFieldFill in the whole draft: { label, kind, description?, options?: [{ value, label, tone? }], format?: { style, currency?, decimals? }, max?, relation?: { target, multiple? }, rollup?: { relation, field, aggregate }, formula?, result? }
UpdatedNameRename the field
PickedKindChange the field's kind
SubmittedFieldSave the field as drafted
ClickedConfirmDeleteasks firstDelete the field and every record's value in it
ClickedCancelClose without saving

Accessibility

  • A modal dialog titled for the field; its name field takes focus when it opens, and Escape closes it without saving.
  • Each choice has a labelled text field, Move up, Move down and Remove buttons named for it, and a color picker whose swatches say their color.
  • Problems and refusals are alerts, and the preview is announced as it changes. Deleting a field asks first, inline.
  • Agents rename, change the kind, save or delete; deleting is marked as consequential.

Source