directus-extension-interface-mustache-value
v2.11.0
Published
Directus interface extension that computes and stores typed values using JavaScript and Mustache.
Maintainers
Readme
directus-extension-interface-mustache-value
Directus interface extension that computes a typed value from JavaScript and Mustache and writes it into the form model.
Behavior
New item:
- does not auto-compute
- stays blank
- does not compute on focus while the route is
/+
Existing item with empty value (
null,undefined, or""):- auto-computes on open
- auto-computes again while dependent fields change, until the field has a value
Existing item with non-empty value:
- computes only when this field receives focus
Read-only / non-editable:
- never computes
Save:
- this extension only updates the form value
- Directus persists it when the user clicks Save
Notes
codeusage is supported by applying this interface tostringortextfields.binaryis intentionally out of scope in this version.- Mustache output is rendered without HTML escaping in the persistence path, so
{{ url }}works as raw text for stored values. - The transform function return value is always used as the Mustache context.
Examples
URL string field
Mustache Template
{{ url }}Integer field
Mustache Template
{{ horas }}JS Transform Function
(fields) => {
return {
horas: 12,
};
};Current decision rules
In simplified form:
if route ends with /+:
keep blank
else if current stored value is null / undefined / "":
auto-compute
else:
compute only on focus