[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationTable form

Table form

ResourceForm is a form over one table's rows that creates, edits or shows a row with the fields, routes and methods the table declares.

ResourceForm is a form over a data controller: pick the table and the mode, and its fields, routes and methods follow. It is the same form a TableView opens for that mode, placed on a page of its own. Use it for a dedicated "New task" page or a record's detail page; use Form to reach an endpoint of your own.

Table form ResourceForm
Connecting to the DMS preview…
Connecting DMS 0.25.8 4 options set
Note

The preview uses serialized resource fields and a fixed record served by the preview service. It renders the same form component as a resource-backed page, but has no write route: editing it does not save anything. In your application, the controller supplies the fields, permissions and persistence shown below.

Usage

src/pages/task-form.ts ts
import { PageController, RegisterPage } from "@antelopejs/interface-dms/page";
import { FormPageLayout } from "@antelopejs/interface-dms/base/layouts";
import { ResourceForm } from "@antelopejs/interface-dms/base/table-view";
import { taskDataAPI } from "../data-api/tasks";

const PAGE_PATH = "/tasks/form";

@RegisterPage()
export class TaskFormPage extends PageController(
  "task-form",
  { displayName: "$app.tasks.form", icon: "i-ph-note-pencil", category: tasksCategory },
  FormPageLayout(),
) {
  static create = ResourceForm(taskDataAPI, {
    mode: "new",
    title: "$app.tasks.new",
    redirectOnSuccess: `${PAGE_PATH}?id={{response._id}}`,
  });

  static edit = ResourceForm(taskDataAPI, { mode: "edit", title: "$app.tasks.edit", labelKey: "name" });

  static view = ResourceForm(taskDataAPI, { mode: "view", title: "$app.tasks.details" });
}

Options

Options of the Table form block
OptionTypeDefaultDescription
mode* Content"new" | "edit" | "view"–Create a row, edit one, or show one read-only.
title Contentstring–
description Contentstring–
submitLabel Contentstring–
successMessage Contentstring–
errorMessage Contentstring–
fieldsOrientation Layout"horizontal" | "vertical"–
redirectOnSuccess Behaviorstring–The page to open once saved; {{response._id}} stands for the row just saved.
modeThe form…
newCreates a row through the controller's new route.
editLoads the row named by rowId, then saves it through edit.
viewLoads the row named by rowId and shows it read-only.

Three modes over the same controller

The three examples below show one of Helio's installation projects through each mode. They are the Form options a ResourceForm serializes to, over the same project fields. The new form starts from the fields' defaults (Residential solar, Planned):

Form Form
Connecting to the DMS preview…
Connecting DMS 0.25.8 4 options set

The edit form loads project CH-0104; its route accepts a save and keeps nothing:

Form Form
Connecting to the DMS preview…
Connecting DMS 0.25.8 5 options set

The view form shows the same record with every field read-only:

Form Form
Connecting to the DMS preview…
Connecting DMS 0.25.8 5 options set

Recipes

Read the row from the route

edit and view read the row id from ?id= by default (QUERY_ROW_ID, {{query.id}}). A page served under a :id route segment passes rowId: ROUTE_PARAM_ROW_ID ({{params.id}}, from @antelopejs/interface-dms/base/table-view) instead. QUERY_ROW_ID comes from @antelopejs/interface-dms/base/resource-form-schema. A form opened by a row action in a drawer, a modal or a side panel passes rowId: "{{row._id}}": it reads the row the container shows, and the next one as the user steps (see Row drawers).

Open the row just created

redirectOnSuccess: "/tasks/form?id={{response._id}}" reopens the page on the row the new form wrote.

Add and remove a photo

The project forms above carry a Site photos image list. Adding a photo uploads the image first, then leaves the record's photo list as an unsaved change: uploading the bytes and saving the record are separate steps. After Save changes, the record holds the photo; removing it marks the list as changed again, and saving writes the empty list. That removes the photo from the record, not the stored file.

The examples on this site run without a backend, so an upload there fails: the upload needs the file routes of a running DMS.

See File storage for upload destinations and storage configuration. The upload URL must reach the storage provider's HTTP route, including when a local frontend proxy sits in front of the backend.

Pitfalls

  • In edit and view, a page reached without its id shows "No entry selected" instead of empty fields (requiresRecord).
  • The form's routes require the action's permission from a table view of the controller that a page mounts: a table form adds no permission of its own. With no such table view, only a platform owner can submit it.

Next steps

Data controller

Declare the table the form is about.

Saving a form

Save bars, footers and instant save.