Skip to content

Fill fields or a list when a selection changes

Choose a customer and copy its address into editable offer fields. Use a synchronous on_change workflow when the values require server data or server recipes.

Complete example: acme_selection_fills_fields

Purpose (translated from upstream README)

Offers. Selecting a customer copies its address into the editable form through a synchronous server workflow. Values are persisted only when saved. Clearing the selection clears the address. Without computation or additional server data, the faster client-only action is recommended (variants/client-on-change.json).
Adapt (translated from upstream README)
Rename all acme_* module, workflow, event and resource identifiers together; update references, layout paths, filters, translation keys and tests. Add fields to the schema, layouts and both languages. Copy files relative to the system root. Add native modules from fixtures/ only when missing; merge existing definitions. Menu entries and preview data are optional. Check variants separately instead of applying them alongside the main definition. Check with php bakery plan <system>, php bakery apply <system>, then php bakery system test-run <system>. In the API repository, AcmeFeatureExamplesTest runs the same plan/apply steps and workflow tests in a disposable PHPUnit system database. These checks do not verify UI rendering or client-only actions.

Files relative to the system root:

acme_selection_fills_fields
├── README.md
├── menu.bake.json
├── modules/
│ ├── acme_customers/
│ │ ├── acme_customers.detail.json
│ │ ├── acme_customers.index.json
│ │ └── acme_customers.module.bake.json
│ └── acme_offers/
│ ├── acme_offers.detail.json
│ ├── acme_offers.index.json
│ └── acme_offers.module.bake.json
├── preview/
│ └── sample.bake.json
├── tests/
│ ├── acme_address_cleared.test.workflow.json
│ └── acme_address_filled.test.workflow.json
├── translations/
│ ├── de.json
│ ├── en.json
│ └── translations.bake.json
├── variants/
│ └── client-on-change.json
└── workflows/
└── acme_fill_offer_address.workflow.bake.json
README.md
README.md
# acme_selection_fills_fields
Angebote / Offers. Kunde wählen: Der synchrone Server-Workflow übernimmt die Adresse ins bearbeitbare Formular; gespeichert wird erst beim Speichern. Leere Auswahl leert die Adresse. Ohne Berechnung oder zusätzliche Serverdaten ist die schnellere reine Client-Aktion empfohlen (siehe variants/client-on-change.json).
## Dateien
- `modules/`: Schema sowie Detail- und Index-Layouts.
- `menu.bake.json`: Navigation (in ein vorhandenes Menü übernehmen).
- `translations/`: deutsche/englische Labels und Bakery-Ressource.
- `workflows/`, `tests/`: ausführbare Graphen und isolierte Business-Tests mit Fixtures.
- `preview/`: optionale Bakery-Beispieldaten; nur in einer Vorschau anwenden.
## Anpassen
Alle `acme_*`-Modul-, Workflow-, Event- und Ressourcen-Identifier gemeinsam umbenennen; Referenzen, Layoutpfade, Filter, Übersetzungsschlüssel und Tests mitändern. Weitere Felder in Schema, Layout und beiden Sprachen ergänzen. Dateien relativ zur Systemwurzel kopieren. Native Module aus `fixtures/` nur ergänzen, wenn sie fehlen; bestehende Definitionen zusammenführen. Menüeinträge und Vorschaudaten sind optional. Varianten separat prüfen, nicht zusätzlich zur Hauptdefinition anwenden.
Prüfen: `php bakery plan <system>`, `php bakery apply <system>`, dann `php bakery system test-run <system>`. In diesem Repository führt `AcmeFeatureExamplesTest` dieselben Plan-/Apply-Schritte und die Workflow-Tests in der wegwerfbaren PHPUnit-Systemdatenbank aus. UI-Darstellung und reine Client-Aktionen sind damit nicht geprüft.
menu.bake.json
menu.bake.json
[
{
"resource_menu": "acme_selection_fills_fields",
"resource": {
"name": "ACME Inc.",
"elements": [
"acme_customers",
"acme_offers"
]
}
}
]
modules/acme_customers/acme_customers.detail.json
modules/acme_customers/acme_customers.detail.json
{
"tabs": [
{
"identifier": "general",
"rows": [
{
"cols": [
{
"span": 24,
"components": [
{
"type": "field_group",
"identifier": "general",
"options": {
"fields": [
"name",
"street",
"zip",
"city"
]
}
}
]
}
]
}
]
}
]
}
modules/acme_customers/acme_customers.index.json
modules/acme_customers/acme_customers.index.json
{
"tabs": [
{
"identifier": "general",
"rows": [
{
"cols": [
{
"span": 24,
"components": [
{
"type": "resource_table",
"identifier": "records",
"options": {
"module": "acme_customers"
}
}
]
}
]
}
]
}
]
}
modules/acme_customers/acme_customers.module.bake.json
modules/acme_customers/acme_customers.module.bake.json
[
{
"resource_module": "acme_customers",
"resource": {
"identifier": "acme_customers",
"title": "name",
"fields": [
{
"identifier": "name",
"type": "text"
},
{
"identifier": "street",
"type": "text"
},
{
"identifier": "zip",
"type": "text"
},
{
"identifier": "city",
"type": "text"
}
],
"layouts": {
"detail": "/modules/acme_customers/acme_customers.detail",
"index": "/modules/acme_customers/acme_customers.index"
}
}
}
]
modules/acme_offers/acme_offers.detail.json
modules/acme_offers/acme_offers.detail.json
{
"tabs": [
{
"identifier": "general",
"rows": [
{
"cols": [
{
"span": 24,
"components": [
{
"type": "field_group",
"identifier": "general",
"options": {
"fields": [
"name",
"customer",
"street",
"zip",
"city"
]
}
}
]
}
]
}
]
}
]
}
modules/acme_offers/acme_offers.index.json
modules/acme_offers/acme_offers.index.json
{
"tabs": [
{
"identifier": "general",
"rows": [
{
"cols": [
{
"span": 24,
"components": [
{
"type": "resource_table",
"identifier": "records",
"options": {
"module": "acme_offers"
}
}
]
}
]
}
]
}
]
}
modules/acme_offers/acme_offers.module.bake.json
modules/acme_offers/acme_offers.module.bake.json
[
{
"resource_module": "acme_offers",
"resource": {
"identifier": "acme_offers",
"title": "name",
"fields": [
{
"identifier": "name",
"type": "text"
},
{
"identifier": "customer",
"type": "select",
"options": {
"references": "acme_customers",
"events": {
"on_change": [
"acme_fill_offer_address"
]
}
}
},
{
"identifier": "street",
"type": "text"
},
{
"identifier": "zip",
"type": "text"
},
{
"identifier": "city",
"type": "text"
}
],
"layouts": {
"detail": "/modules/acme_offers/acme_offers.detail",
"index": "/modules/acme_offers/acme_offers.index"
}
}
}
]
preview/sample.bake.json
preview/sample.bake.json
[
{
"resource_entity": "acme_sample_customer",
"resource": {
"module": "acme_customers",
"fields": {
"name": "ACME Inc.",
"street": "Example Street 1",
"zip": "12345",
"city": "Example City"
}
}
},
{
"resource_entity": "acme_sample_offer",
"depends_on": "resource_entity.acme_sample_customer",
"resource": {
"module": "acme_offers",
"fields": {
"name": "ACME Offer",
"customer": "${resource_entity.acme_sample_customer}"
}
}
}
]
tests/acme_address_cleared.test.workflow.json
tests/acme_address_cleared.test.workflow.json
{
"identifier": "acme_address_cleared",
"workflow": "acme_fill_offer_address",
"fixtures": [
{
"type": "entity",
"module": "acme_customers",
"alias": "customer",
"fields": {
"name": "ACME Inc.",
"street": "Example Street 1",
"zip": "12345",
"city": "Example City"
}
},
{
"type": "entity",
"module": "acme_offers",
"alias": "offer",
"fields": {
"name": "ACME Offer"
}
}
],
"trigger": {
"type": "dispatch_sync",
"entry": "acme_fill_offer_address",
"data": {
"prototype": "fixture:offer",
"selector": "$.customer",
"value": null
}
},
"assertions": [
{
"type": "response_json_path_equals",
"path": "set.0.value",
"value": ""
},
{
"type": "response_json_path_equals",
"path": "set.1.value",
"value": ""
},
{
"type": "response_json_path_equals",
"path": "set.2.value",
"value": ""
},
{
"type": "response_json_path_equals",
"path": "save",
"value": false
}
]
}
tests/acme_address_filled.test.workflow.json
tests/acme_address_filled.test.workflow.json
{
"identifier": "acme_address_filled",
"workflow": "acme_fill_offer_address",
"fixtures": [
{
"type": "entity",
"module": "acme_customers",
"alias": "customer",
"fields": {
"name": "ACME Inc.",
"street": "Example Street 1",
"zip": "12345",
"city": "Example City"
}
},
{
"type": "entity",
"module": "acme_offers",
"alias": "offer",
"fields": {
"name": "ACME Offer",
"customer": "fixture:customer"
}
}
],
"trigger": {
"type": "dispatch_sync",
"entry": "acme_fill_offer_address",
"data": {
"prototype": "fixture:offer",
"selector": "$.customer",
"value": "fixture:customer"
}
},
"assertions": [
{
"type": "response_json_path_equals",
"path": "set.0.value",
"value": "Example Street 1"
},
{
"type": "response_json_path_equals",
"path": "set.1.value",
"value": "12345"
},
{
"type": "response_json_path_equals",
"path": "set.2.value",
"value": "Example City"
},
{
"type": "response_json_path_equals",
"path": "save",
"value": false
}
]
}
translations/de.json
translations/de.json
{
"modules": {
"acme_customers": {
"title": "Kunden",
"fields": {
"name": "Name",
"street": "Straße",
"zip": "Postleitzahl",
"city": "Ort"
},
"tabs": {
"general": "Allgemein"
}
},
"acme_offers": {
"title": "Angebote",
"fields": {
"name": "Name",
"customer": "Kunde",
"street": "Straße",
"zip": "Postleitzahl",
"city": "Ort"
},
"tabs": {
"general": "Allgemein"
}
}
}
}
translations/en.json
translations/en.json
{
"modules": {
"acme_customers": {
"title": "Customers",
"fields": {
"name": "Name",
"street": "Street",
"zip": "Postal code",
"city": "City"
},
"tabs": {
"general": "General"
}
},
"acme_offers": {
"title": "Offers",
"fields": {
"name": "Name",
"customer": "Customer",
"street": "Street",
"zip": "Postal code",
"city": "City"
},
"tabs": {
"general": "General"
}
}
}
}
translations/translations.bake.json
translations/translations.bake.json
[
{
"resource_translations": "de",
"resource": {
"identifier": "de",
"code": "de_DE",
"name": "Deutsch",
"dir": "ltr",
"provider": "deDE",
"data": "${file('translations/de.json')}"
}
},
{
"resource_translations": "en",
"resource": {
"identifier": "en",
"code": "en_US",
"name": "English",
"dir": "ltr",
"provider": "enUS",
"data": "${file('translations/en.json')}"
}
}
]
variants/client-on-change.json
variants/client-on-change.json
{
"events": {
"on_change": [
{
"action": "set",
"fields": {
"street": "this.customer ? this.customer.street : \"\"",
"zip": "this.customer ? this.customer.zip : \"\"",
"city": "this.customer ? this.customer.city : \"\""
}
}
]
}
}
workflows/acme_fill_offer_address.workflow.bake.json
workflows/acme_fill_offer_address.workflow.bake.json
[
{
"resource_workflow": "acme_fill_offer_address",
"resource": {
"identifier": "acme_fill_offer_address",
"title": "ACME Inc. — acme_fill_offer_address",
"active": true,
"async": false,
"entry": "acme_fill_offer_address",
"elements": [
{
"name": "acme_fill_offer_address",
"type": "event/on_change",
"options": {
"module": "acme_offers"
},
"set": {
"offer": "prototype:"
},
"to": {
"default": {
"fill": [
"default"
]
}
}
},
{
"name": "fill",
"type": "action/set",
"options": {
"recipes": {
"street": "$offer.customer ? $offer.customer.street : \"\"",
"zip": "$offer.customer ? $offer.customer.zip : \"\"",
"city": "$offer.customer ? $offer.customer.city : \"\""
}
},
"in": {
"default": "$offer"
},
"to": {}
}
],
"events": [
{
"identifier": "acme_fill_offer_address",
"type": "on_change",
"module": "acme_offers"
}
]
}
}
]

Source: brezel/api@572da72238ad1aab7b60287c898eaede2c08a876

Agents: system_authoring_command reference kind=feature query=acme_selection_fills_fields

The select field names the registered event/on_change event. Its prototype contains the unsaved offer; action/set returns assignments for the form. Clearing the customer clears the address. These responses do not save anything. There is no event/change element.

For an editable list, action/set.options.add appends objects; recipes replaces the whole list. Use a selector that already exists in the prototype, e.g. $.items. The SPA assigns row indexes. See form response selectors.

Copy the example files relative to your system root. Merge existing native modules, menus and roles; rename all related identifiers together. Apply preview data only in a disposable preview. Run the plan, apply and tests against that preview:

Terminal window
php bakery plan <system>
php bakery apply <system>
php bakery system test-run <system>

acme_address_filled dispatches the on-change entry with prototype, selector and value, then checks set.*.value and save: false. acme_address_cleared tests an empty selection. Also check selecting, clearing and editing in the browser: workflow tests do not exercise the SPA.

  • Recommended for simple copies without computation or extra server data: the faster client-only options.events.on_change action. Use the supplied variants/client-on-change.json instead of the server event; check it in the browser. It cannot enforce API behavior.
  • Recommended for derived values that users should not edit: top-level field recipe. Computed inputs are locked. List-returning recipes still need a target-system check.
  • Recommended for guarantees on REST writes: event/create or event/update → op/set → action/save. Guard follow-up saves against recursion.
  • Recommended for child records with their own identity or permissions: flow/each → source/new → action/save, displayed through a related table.
  • Not recommended for changing ordinary saved values: beforeSave + op/set; normal UI/REST saving freezes values before that event.

Field options · Recipes by runtime · Form responses · Workflow tests · Assertions