M8-S3 — Expose it with no code: the web control
Section titled “M8-S3 — Expose it with no code: the web control”| Module | M8 — Extend the engine from source (source strand) |
| After this session you can | Give a new field type a web control that the designer offers to builders, and verify it in the designer and the portal. |
| Time | 69 min with a facilitator · about 69 min on your own |
| Before you start | M8-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 deeper | Frontend 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”The contract, recalled and made concrete
Section titled “The contract, recalled and made concrete”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:
| Piece | What it does | For Meter reading |
|---|---|---|
| Edit control | A 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 control | A read-only component on the view base class | Shows “4.2 mm/s” as text |
| Proxies | Tiny files that let the registry load each component lazily | One per component |
| Metadata | Declares the component’s id, its data types, the options a builder may set, and what it supports | Unit, minimum, maximum; not searchable, not a title, not filterable |
| Plugin registration | Lists the components (id and proxy) and their metadata | Built-in, or a tenant-gated plugin |
| Labels | The 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: text, never markup
Section titled “The view control: text, never markup”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 (
MeterReadingonly); - 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.
Built-in or tenant-gated
Section titled “Built-in or tenant-gated”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-in | Tenant-gated custom plugin | |
|---|---|---|
| Who sees it in the designer | Every tenant | Tenants whose configuration lists it |
| Fits | A type accepted upstream as part of the platform | A pilot, or a capability sold to some tenants |
| Risk | A half-finished control appears everywhere | Forgetting 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.
-
Find its pieces by id.
Terminal window grep -rln "NumberComponent" libs/shared/dynamic-fields/src | headExpected: the edit component, its proxy, the view component and its proxy, and the metadata file.
-
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. -
Open the edit component. Notice
writeValue, where the change callback is called, andvalidate, which reads the field’s options. -
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
- Beside the Number control, create the edit component
MeterReadingInputComponent, extending the field-control base class withDataTypeEnum.MeterReadingand the value shape{value, unit}. Render a number input and, after it, the unit from the field’s options as plain text. - Implement
writeValue(v): showv?.valuein the input, or empty fornull. - On every input change, call the change callback with
{value: <the number>, unit: <the field's unit>}, ornullwhen the input is empty. - 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’sminor above itsmaxwhen they are set. - Create the view component
MeterReadingViewComponenton the view base class. Show{{ value?.value }} {{ value?.unit }}with normal text binding; nothing else. - Create a proxy file for each component, following the Number proxies.
- Add two metadata entries with the metadata factory: the edit control (id
MeterReadingInputComponent, data types[DataTypeEnum.MeterReading], optionsunit,min,maxwith validations, paired viewMeterReadingViewComponent, not searchable, no title or main number role, not queryable) and the view control. - List both components (id and proxy) and both metadata entries in the same plugin configuration as Number.
- Add the labels in English and Arabic: the palette name “Meter reading” / «قراءة عدّاد», and the option names “Unit” / «الوحدة», “Minimum” / «الحدّ الأدنى», “Maximum” / «الحدّ الأقصى».
- Save. Expected: the development server recompiles without errors.
Use it as a builder
- In the portal, open Administration › Applications › Modules, open Asset Maintenance, then the Assets entity, and select the Structure tab.
- Find Meter reading in the palette and drag it onto the structure. Name it Last vibration reading / «آخر قراءة اهتزاز».
- 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.
- 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.
- 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
-
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"}. -
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.
-
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.
-
Open the Structure of Work Orders: Meter reading is offered there too. Do not add it yet; Omar Haddad does that in M8-S4.
-
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 see | What to do |
|---|---|
| Meter reading is not in the palette | The 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 nothing | The view control is not paired or not exposed: check the metadata’s paired component and its proxy entry. |
| The form accepts 80 | validate() 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 editing | The change callback is never called. See the trap in M0-S1. |
The API shows 4.2 instead of an object | The 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”After release, a developer renames the control’s id from MeterReadingInputComponent to
MeterReadingControl “for consistency”. What happens to existing fields?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
Larkspur wants the control for its own tenant now, before the platform’s engineering has accepted the type upstream. How do you register it?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
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?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
↺ Recap (1 min) — What you can now do
Section titled “↺ Recap (1 min) — What you can now do”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.