> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/design/pro-code/custom-object-editor.md).

# Custom Object Editor

Custom object editors allow customizing form screens used for viewing and editing single item records

Set the screen's editor to `ObjectEditorCustomCode` and put your code in the editor configuration. Your component replaces the whole record form: header, fields, save/delete buttons.

The platform still gives you the working copy of the record, change tracking, and a ready-made set of actions.

**Use `props.events()` for saving**

`events` is a **function** that returns the action bundle:

```jsx
const { onSave, onNew, onDelete, onClose, onReload } = props.events();
```

Prefer `events().onSave()` over calling `props.onSave` directly. It takes no arguments, runs schema validation when the editor is configured as validated, reports validation errors to the user and honours the "close after save" setting. Calling `props.onSave` yourself skips all of that.

**Locale switching**

If the editor configuration lists `locales`, a locale switcher is provided around your component and localised fields resolve against the selected locale. Without it, that layer is disabled.

**Component key**

The fallback key for a custom editor is derived from the data source, but the source is not passed down to editors, so it commonly resolves to the same value for **every** custom editor in the application. That doesn't break anything (the cache verifies your source before reusing it), but it does mean your editors recompile whenever you switch between them.

Set the component key (`editorType`) explicitly in the editor configuration.

## Custom object editor properties

### Data

| Prop            | Shape                            | Notes                                                                        |
| --------------- | -------------------------------- | ---------------------------------------------------------------------------- |
| `data`          | the working copy of the record   | already merged with configured defaults                                      |
| `changes`       | `{ [path]: { value, counter } }` | the paths edited since load                                                  |
| `changeCounter` | number                           | `0` means pristine, which is useful for disabling Save                       |
| `schema`        | JSON Schema                      |                                                                              |
| `ui`            | object                           | your editor configuration                                                    |
| `open`          | boolean                          | for dialog-style editors                                                     |
| `readOnly`      | boolean                          |                                                                              |
| `snapshot`      | `string \| null`                 | set when viewing a historic version                                          |
| `id`            | `string`                         | a **path expression** for where the id lives (e.g. `"id"`), not the id value |
| `name`          | `string`                         | a path or expression for the display name                                    |

> `source` is **not** passed to editors. Don't rely on `props.source` here.

### Actions

| Prop          | Signature                                                                         |
| ------------- | --------------------------------------------------------------------------------- |
| `events`      | `() => ({ onSave, onNew, onDelete, onChange, onClose, onReload, specialEvents })` |
| `onChange`    | `(value, path)`                                                                   |
| `onSave`      | `(item, changes, force, callback)`; raw, prefer `events().onSave()`               |
| `onDelete`    | `(record, callback)`                                                              |
| `onNew`       | `(data?)`                                                                         |
| `onClose`     | `()`                                                                              |
| `onReload`    | `()`                                                                              |
| `sendMessage` | `(text, severity, detail)`                                                        |
| `dispatch`    | Redux `dispatch`                                                                  |

`onChange` paths are dotted, with square brackets around any segment that itself contains dots:

```js
props.onChange("New title", "data.title");
props.onChange(9.99, "data.prices[tr-TR].amount");
props.onChange(wholeRecord, "$");        // "$" replaces the entire record
```

Passing `undefined` or `null` **removes** the key rather than storing a null.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/design/pro-code/custom-object-editor.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
