Skip to content

M8-S3 — Expose it with no code: the web control

Section titled “M8-S3 — Expose it with no code: the web control”
ModuleM8 — Extend the engine from source (source strand)
After this session you canGive a new field type a web control that the designer offers to builders, and verify it in the designer and the portal.
Time69 min with a facilitator · about 69 min on your own
Before you startM8-S2 done: MeterReading in all three code bases, caster tests green. Your source workbench running with the Larkspur suite. M3-S5 (the plugin system) and the no-code guarantee checklist open.
Go deeperFrontend architecture: the plugin system · Field configuration reference

◆ Orientation (1 min) — From engine to palette

Section titled “◆ Orientation (1 min) — From engine to palette”

The engine now knows what a meter reading is. No builder can use it yet: the designer offers only the controls registered in the web front end, and the portal can show only values a control knows how to draw. In this session you write that control, declare it so the designer offers it with a unit and a range that the builder sets, and see a planner’s field work end to end, from palette to stored record.

▤ Concept (6 min) — What a field control is made of

Section titled “▤ Concept (6 min) — What a field control is made of”

In M3-S5 you saw how the web front end draws configuration: a field definition names its edit and view components by a text id, a registry turns that id into a component class, loaded the first time it is needed, and a metadata store tells the designer which controls exist and what can be configured on each. Building a control means supplying each of those pieces:

PieceWhat it doesFor Meter reading
Edit controlA component on the field-control base class; it is a form control (writeValue, the change callback, validate)An input for the number, the field’s unit beside it, the range check
View controlA read-only component on the view base classShows “4.2 mm/s” as text
ProxiesTiny files that let the registry load each component lazilyOne per component
MetadataDeclares the component’s id, its data types, the options a builder may set, and what it supportsUnit, minimum, maximum; not searchable, not a title, not filterable
Plugin registrationLists the components (id and proxy) and their metadataBuilt-in, or a tenant-gated plugin
LabelsThe palette and option names, in English and Arabic“Meter reading”, “Unit”, “Minimum”, “Maximum”

What to notice: the component’s text id is stored in every field definition that uses it, exactly like the data-type number. It is a contract: choose it once, and never rename it.

The edit control: a form control that knows its field

Section titled “The edit control: a form control that knows its field”

The edit control extends the platform’s field-control base class with your data type and value shape. The base class makes it a normal reactive-form control and gives it the field: its definition, including the options the builder chose for this field. That is why the per-field range lives here and not in the caster (M8-S2): the control can read min and max from the field’s options and refuse a value outside them in validate().

The source-strand check in M0-S1 named the trap: a control that shows values but never calls the change callback looks fine and silently loses every edit. Call it whenever the number changes, with the whole stored shape, {value, unit}, not the bare number.

The view control shows a stored reading in lists, cards and records. Show it as text: number, space, unit. A unit is typed by builders and readings arrive from feeds; inserting either into the page as markup would reopen the cross-site scripting class from M5-S3. The framework escapes text by default; the mistake would be to switch that off.

The metadata: what the designer offers, and what it must not

Section titled “The metadata: what the designer offers, and what it must not”

The metadata factory fills sensible defaults, and you override what matters:

  • the component id and the data types it handles (MeterReading only);
  • the options a builder sets per field (unit as text; minimum and maximum as numbers, each with its own validation so a builder cannot set a minimum above the maximum);
  • the paired view control, so the designer picks the right one;
  • the capability flags. Here you declare the decisions from M8-S2’s touch-point table: not searchable, not usable as a title or main number, not filterable. A flag left at a default that claims support would let a builder configure something the engine does not do.

A control can be registered two ways. A built-in control is part of the internal plugins the web front end loads at start-up, and every tenant’s designer offers it. A custom plugin control is marked as such in its metadata and is offered only to tenants whose runtime configuration lists it, so one web build can show different palettes to different tenants.

Built-inTenant-gated custom plugin
Who sees it in the designerEvery tenantTenants whose configuration lists it
FitsA type accepted upstream as part of the platformA pilot, or a capability sold to some tenants
RiskA half-finished control appears everywhereForgetting to list it: the field type exists but no builder can pick it

What to notice: gating hides the control from the palette; it does not remove the data type from the engine. A tenant without the control that imports a package containing a Meter reading field still stores the values, but its designer and portal cannot draw them.

For the lab you register the control as built-in on your workbench, because the type is meant to go upstream (M8-S1’s “it will be carried” test). During a real pilot you would gate it, and the capstone lets you choose.

▶ Guided demo (7 min) — Read the Number control

Section titled “▶ Guided demo (7 min) — Read the Number control”

Starting state. The web workspace on feat/meter-reading. You will follow the closest existing control, Number, through its pieces.

  1. Find its pieces by id.

    Terminal window
    grep -rln "NumberComponent" libs/shared/dynamic-fields/src | head

    Expected: the edit component, its proxy, the view component and its proxy, and the metadata file.

  2. Open the metadata entry for Number. Notice the component id, the data types, the options (min, max, step) each with a validation, and the paired view component.

  3. Open the edit component. Notice writeValue, where the change callback is called, and validate, which reads the field’s options.

  4. Open the plugin configuration that lists Number in its exposed components and its metadata, and find where that configuration is loaded at start-up. That is where your control will be listed.

Screenshot pending The Number control's metadata entry in the editor, with the component id, data types, options with validations and the paired view component highlighted What to notice: everything the designer shows about a Number field comes from this one entry: which options appear, which are validated, and which view control draws the value.

⛏ Lab (48 min) — Build the Meter reading control and use it as a builder

Section titled “⛏ Lab (48 min) — Build the Meter reading control and use it as a builder”

Goal. A Meter reading control the designer offers, with a unit and a range per field, that the portal edits and shows, and whose stored value you read through the API.

Before you start. Your source workbench running (services, web development server); signed in as your administrator; the Larkspur suite seeded; $BASE and $TOKEN set as in the workbench.

Write the pieces

  1. Beside the Number control, create the edit component MeterReadingInputComponent, extending the field-control base class with DataTypeEnum.MeterReading and the value shape {value, unit}. Render a number input and, after it, the unit from the field’s options as plain text.
  2. Implement writeValue(v): show v?.value in the input, or empty for null.
  3. On every input change, call the change callback with {value: <the number>, unit: <the field's unit>}, or null when the input is empty.
  4. Implement validate(): return no error for an empty optional field; an error for a value that is not a finite number; an error for a value below the field’s min or above its max when they are set.
  5. Create the view component MeterReadingViewComponent on the view base class. Show {{ value?.value }} {{ value?.unit }} with normal text binding; nothing else.
  6. Create a proxy file for each component, following the Number proxies.
  7. Add two metadata entries with the metadata factory: the edit control (id MeterReadingInputComponent, data types [DataTypeEnum.MeterReading], options unit, min, max with validations, paired view MeterReadingViewComponent, not searchable, no title or main number role, not queryable) and the view control.
  8. List both components (id and proxy) and both metadata entries in the same plugin configuration as Number.
  9. Add the labels in English and Arabic: the palette name “Meter reading” / «قراءة عدّاد», and the option names “Unit” / «الوحدة», “Minimum” / «الحدّ الأدنى», “Maximum” / «الحدّ الأقصى».
  10. Save. Expected: the development server recompiles without errors.

Use it as a builder

  1. In the portal, open Administration › Applications › Modules, open Asset Maintenance, then the Assets entity, and select the Structure tab.
  2. Find Meter reading in the palette and drag it onto the structure. Name it Last vibration reading / «آخر قراءة اهتزاز».
  3. Open the field’s settings: set Unit to mm/s, Minimum to 0 and Maximum to 50. Select Save, then Save Changes.

Screenshot pending The Assets entity's Structure tab with Meter reading in the palette and the new field's settings open, showing Unit mm/s, Minimum 0 and Maximum 50 What to notice: the options are the ones your metadata declared, with the labels you added; nothing about the field needed code from the builder.

  1. Open the Assets records in the portal, open Pump P-104, edit it, and type 80 in Last vibration reading. Expected: the form refuses the value and names the range.
  2. Type 4.2 and save. Expected: the record shows 4.2 mm/s.

Screenshot pending The Pump P-104 edit form with Last vibration reading showing 80 and a range message under it What to notice: the range is checked in the control, from this field’s options; another field of the same type can have a different range.

Read what was stored

  1. Read the record through the API and look at the field:

    Terminal window
    curl -s -H "x-app-token: $TOKEN" "$BASE/api/v2/entities/assets/entries?search=P-104" \
    | jq '.result[0].value.last_vibration_reading'

    Expected: {"value": 4.2, "unit": "mm/s"}.

  2. Switch the portal to Arabic and open Pump P-104 again. Expected: the field’s Arabic name, and the value shown as 4.2 mm/s.

  3. In the designer, open Last vibration reading again and look for its search, title and filter options. Expected: none of them offered, as your metadata declared.

  4. Open the Structure of Work Orders: Meter reading is offered there too. Do not add it yet; Omar Haddad does that in M8-S4.

  5. Commit the web changes on feat/meter-reading.

Check.

  • The development server compiles with your control.
  • Meter reading appears in the designer’s palette, with English and Arabic labels.
  • Last vibration reading on Assets has unit mm/s and range 0 to 50.
  • The portal refuses 80 and accepts 4.2.
  • The record shows 4.2 mm/s in English and Arabic.
  • The API shows the stored value as {"value": 4.2, "unit": "mm/s"}.
  • The field offers no search, title or filter options.
  • Your web changes are committed.

Pass condition. A builder can add a Meter reading field with its own unit and range in the designer, the portal enforces the range, and the stored value has the shape the engine defined.

If something goes wrong

What you seeWhat to do
Meter reading is not in the paletteThe plugin configuration does not list the metadata, or the metadata’s data types do not include the new type, or the label key is missing. Check all three; reload the designer.
The field saves, but the portal shows nothingThe view control is not paired or not exposed: check the metadata’s paired component and its proxy entry.
The form accepts 80validate() is not reading the field’s options, or the options’ names differ from the metadata’s. Log the field’s options once to compare.
The old value is saved after editingThe change callback is never called. See the trap in M0-S1.
The API shows 4.2 instead of an objectThe control sent the bare number and the caster is not running: rebuild the data service from M8-S2 and save again.
Model answer

The edit control’s heart (simplified):

writeValue(v: MeterReadingValue | null): void {
this.input = v?.value ?? null;
}
onInput(n: number | null): void {
this.input = n;
this.onChange(n === null ? null : {value: n, unit: this.field.renderOptions.editComponent.options?.unit ?? null});
}
validate(): ValidationErrors | null {
const o = this.field.renderOptions.editComponent.options ?? {};
if (this.input === null) return null;
if (!Number.isFinite(this.input)) return {meterReading: 'not-a-number'};
if (o.min != null && this.input < o.min) return {meterReading: 'below-min'};
if (o.max != null && this.input > o.max) return {meterReading: 'above-max'};
return null;
}

The metadata decisions that matter: the id MeterReadingInputComponent (a stored contract); dataTypes: [DataTypeEnum.MeterReading]; options unit, min, max with validations; paired with MeterReadingViewComponent; not searchable; no title or main-number role; not queryable.

Built-in, and why: the type is meant to be carried upstream; on a pilot tenant you would mark it as a custom plugin and list it in that tenant’s configuration instead.

The stored value read back: {"value": 4.2, "unit": "mm/s"}, the caster’s shape, whatever the control sent.

✓ Practice (6 min) — The control’s contract

Section titled “✓ Practice (6 min) — The control’s contract”
PracticeChoose one answer.

After release, a developer renames the control’s id from MeterReadingInputComponent to MeterReadingControl “for consistency”. What happens to existing fields?

  1. Explanation for A

    ✗ Incorrect

    Not this one: fields name their edit and view components by text id, and the registry resolves the stored id. See the contract.

  2. Explanation for B

    ✓ Correct

    Correct: the id is stored in every field definition that uses the control, so renaming it breaks them all. See the contract.

  3. Explanation for C

    ✗ Incorrect

    Not this one: values are stored under the field’s name and survive; it is the drawing of them that breaks. See the contract.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

A reviewer finds that the view control builds its display by inserting the unit into the page as markup, “so units like m3 look right”. What do you answer?

  1. Explanation for A

    ✓ Correct

    Correct: text that others typed must never become active content; superscripts can be typed as characters instead. See the view control.

  2. Explanation for B

    ✗ Incorrect

    Not this one: builders make mistakes and accounts are compromised, and “only our own staff” is not a control. See M5-S3.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the unit is the risky part here, and escaping one value while inserting the other as markup leaves the hole open. See the view control.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

The metadata of the Meter reading control is left with the factory’s defaults for search and title roles. Why is that a no-code problem rather than just a missing feature?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the defaults are switched in metadata by the developer; the problem is what builders are then offered. See the metadata.

  2. Explanation for B

    ✗ Incorrect

    Not this one: search and title roles have nothing to do with encryption; they control what the designer offers. See the metadata.

  3. Explanation for C

    ✓ Correct

    Correct: what the designer offers is a promise; a promise the engine cannot keep breaks the builder’s no-code experience. See the metadata.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

Larkspur wants the control for its own tenant now, before the platform’s engineering has accepted the type upstream. How do you register it?

  1. Explanation for A

    ✗ Incorrect

    Not this one: built-in controls appear in every tenant’s designer, including tenants that never asked for an unaccepted type. See built-in or tenant-gated.

  2. Explanation for B

    ✓ Correct

    Correct: gating lets one web build show the control to the pilot tenant only, until it is accepted upstream. See built-in or tenant-gated.

  3. Explanation for C

    ✗ Incorrect

    Not this one: an unlisted custom control is offered to no tenant, so Larkspur’s builders could not pick it either. See built-in or tenant-gated.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

The portal refuses 80 for Last vibration reading. A nightly import then writes 80 into the same field through the API. What is stored, and why?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the caster never sees the field’s options, so it cannot know this field’s range. See M8-S2: the range check.

  2. Explanation for B

    ✗ Incorrect

    Not this one: controls run in the browser; an import through the API never passes through one. See the edit control.

  3. Explanation for C

    ✓ Correct

    Correct: this is the recorded trade-off; writers that bypass the controls are checked only for a well-formed reading. See M8-S2: the range check.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

You can give an engine-level field type its web control: an edit control that is a proper form control and enforces the field’s own range, a view control that shows text and never markup, metadata that offers builders exactly what the engine supports and declares what it does not, and a registration chosen between built-in and tenant-gated for a reason. A planner’s field now works from palette to stored record without the planner writing anything.

Next. In M8-S4 you take the type to the phone, or declare its fallback, and Omar Haddad proves the no-code guarantee for the whole extension on the web and the phone.