ObjectStackObjectStack

Create form vs edit form — the differences

One flat, grouped field set gives both the create form and the edit form. Leave a field out of create with its showOnCreate switch; there is no second form to maintain.

Scenario

The form for creating a record should ask only a handful of fields (the essentials). The form for editing an existing record shows the full record, grouped into sections. How do I model this without maintaining two field lists that drift apart?

Author one field set on the object. Group it with fieldGroups, and mark the fields a create should not ask for with showOnCreate: false. The Console's create and edit forms both come from that one set. They do not load an internal form view (form, formViews.default or formViews.create); an app that still declares one installs and runs, the form changes nothing on create or edit, and os validate reports it as form-view-internal-not-loaded. A default or create form that a form action opens by name (its target is the form's served name, written out) still loads where that action opens it, and is not reported.

1. Put the intent on the fields

The create form is the edit form minus the fields a create should not ask for, and those are named by signals that already live on each field:

Field signalEffect on the create form
required: truemust appear on create; showOnCreate: false beside it is refused at parse
showOnCreate: falseleft out of create; still on edit, the record page and lists
readonly / formula / rollup / autonumber / system-stampednever on create (you can't set it)
defaultValue presentself-fills, so it is a good candidate for showOnCreate: false
hiddenoff everywhere by default
visibleWhen / readonlyWhen / requiredWhenevaluated on create and edit alike
groupwhich section the field belongs to (only once that group is declared in fieldGroups; see §2)
declaration orderthe order you write fields in is the default order everywhere — there is no field.order

2. Sections come from field.group, as authorized by fieldGroups

field.group on its own does not create a section. The authorization source is the object's fieldGroups declaration: deriveFieldGroupLayout (ADR-0085 §5) — the single derivation every renderer and the i18n walker consume — sections only those fields whose group matches a declared fieldGroups[].key.

  • An undeclared group renders exactly like no group at all: the field drops into the trailing bucket of ungrouped fields, which the form and the record page draw under their own Other heading (translated per locale) after the declared groups.
  • Declare no fieldGroups at all and grouping does not apply — the derivation yields nothing and you get a flat form.
  • Either way, os lint (and os build / os validate) reports every unmatched reference as field-group-undeclared.
  • A master-detail sub-table is a group's relatedList: it is drawn in that group's place on create and edit.

3. Leave a field out of create

import { ObjectSchema, Field } from '@objectstack/spec/data';

export const Contact = ObjectSchema.create({
  name: 'showcase_contact',
  label: 'Contact',
  sharingModel: 'private',
  fields: {
    name: Field.text({ label: 'Full name', required: true, group: 'contact' }),
    email: Field.email({ label: 'Email', required: true, group: 'contact' }),
    phone: Field.text({ label: 'Phone', group: 'contact' }),
    company: Field.text({ label: 'Company', group: 'work' }),
    // Edit-time only: the create form does not ask for it.
    notes: Field.text({ label: 'Notes', maxLength: 4000, group: 'notes', showOnCreate: false }),
  },
  fieldGroups: [
    { key: 'contact', label: 'Contact' },
    { key: 'work', label: 'Work' },
    { key: 'notes', label: 'Notes' },
  ],
});

New draws the Contact and Work sections; Edit draws all three. In Studio, the field's Show on create switch writes the same key; it stays on, and locked, for a required field.

Every create entry reads this: the list's Add button (AddRecordConfigSchema says only whether it shows and where), the object's New, the full-page create and a create an action opens.

Why

Two independent full forms are the Salesforce page-layout tax: add a required field, forget the create form → runtime "missing required field" on create; rename a field → silent drift. With one field set, the create form can only differ from the edit form by the fields marked showOnCreate: false, and a required field can never be one of them.

The create fields are a subset of the edit fields in the same order and groups, so "quick-create a few fields → save → land on the full record" stays visually continuous.

What about a form view?

A public form (sharing.enabled: true) keeps loading at its own link by its own definition, and a named form an action of type form opens keeps loading by its name. Those are the places a hand-written form view still belongs. The object's own create and edit forms are not: their sections come from the object's fieldGroups, and their fields, rules and defaults from the fields themselves.

Runnable example

Where the form opens is a separate choice from what it holds, made on the object:

import { ObjectSchema } from '@objectstack/spec/data';

export const Account = ObjectSchema.create({
  name: 'account',
  label: 'Account',
  sharingModel: 'private',
  editMode: 'page', // 'modal' (the Console's default) | 'page'
  fields: { name: { type: 'text', label: 'Name', required: true } },
});
  • modal opens Create and Edit in a dialog over the current view: short forms and quick edits.
  • page gives the form its own route under the active app, /apps/:appName/:objectName/new and /apps/:appName/:objectName/record/:recordId/edit: a URL that can be bookmarked and shared, survives a refresh (the form re-reads the record from the URL) and closes with Back. It suits long forms.

Both render the same form, so sections, validation and visibility rules behave identically. The change is additive: the existing Create and Edit entry points, the list's per-row Edit included, follow editMode with no other edit. To open the page routes from a page element, an action:button names the Console's navigate_create or navigate_edit handler in properties.actionType, with its arguments in properties.params (a node-level params is the action's input list and is ignored here). Strings in properties.params are templates, so a button on a record page names its record with ${record.id}; inside an object view the active object is already known and params can be omitted.

{
  "type": "action:button",
  "properties": {
    "label": "Edit",
    "icon": "pencil",
    "actionType": "navigate_edit",
    "params": { "objectName": "account", "recordId": "${record.id}" }
  }
}

Anti-patterns

  • Two full hand-authored field lists (contact_create_form + contact_edit_form). Guaranteed drift; the create form silently misses new required fields.
  • Writing form or formViews.create to shape create or edit. Neither is loaded; group the fields and use showOnCreate instead.
  • Restating field type / validation / options on a form. Data semantics live on the object only.

See also

On this page