Skip to content

Commit 2808a8b

Browse files
authored
Merge pull request #10 from IntentFile/spec/default-value-seeds-new-rows
spec: defaultValue seeds a new row, not only the column
2 parents eef03ce + 6144faf commit 2808a8b

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

docs/public/logo.png

5.52 KB
Loading

docs/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The quick lookup surface: one line and a minimal snippet per construct. For rule
1212
| [`entities`](/spec/entities) | tables + CRUD UI + a generated data layer & API |
1313
| [field / relation attributes](/spec/entities#fields) | uniqueness, layout, read-only, dropdown filtering, cascades |
1414
| [`pattern`](/spec/entities#fields) | an input-format regular expression enforced in the UI and server-side |
15+
| [`defaultValue`](/spec/entities#defaultvalue-field-defaults) | a field default: column default, satisfies `required`, and seeds a new row in the UI |
1516
| [`dependsOn`](/spec/relations) | link a dropdown to another, copy a value from the referenced record, or default a line from the open document header |
1617
| [`function`](/spec/entities#function-the-presentation-role) | an explicit presentation role (Document, Setting, ...) |
1718
| [`label`](/spec/entities#label-a-stored-display-name) | a stored, read-only display name for lookups |

docs/spec/entities.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fields:
3737
| `required` | NOT NULL; the generated required-value validation keys on this. A field that also carries a default (`defaultValue`, or `init` on a relation) is NOT demanded from the caller - the default satisfies it |
3838
| `length` | column length for string types |
3939
| `pattern` | an input-format regular expression the value must match (string / text fields only) |
40-
| `defaultValue` | column default |
40+
| `defaultValue` | the field's default: the column default, the reason a `required` field is not demanded from the caller, and the value a **new** row is seeded with in the UI (see [Field defaults](#defaultvalue-field-defaults)) |
4141
| `unique` | a UNIQUE constraint (e.g. a code or business key) |
4242
| `precision` / `scale` | override the decimal default (16, 2) |
4343
| `readOnly` | rendered read-only in the UI (e.g. a calculated total) |
@@ -85,6 +85,28 @@ By default the generated UI controls follow declaration order - all fields first
8585

8686
Names match field / relation names (case-insensitive). A partial order is fine - any property not listed keeps its default position and is appended after the listed ones.
8787

88+
## defaultValue — field defaults
89+
90+
`defaultValue` states what a field holds when nobody supplies a value:
91+
92+
```yaml
93+
fields:
94+
- { name: hours, type: decimal, required: true, defaultValue: 8 }
95+
- { name: billable, type: boolean, defaultValue: true }
96+
```
97+
98+
It has three effects at once, which are deliberately one key rather than three:
99+
100+
- it is the **column default**, so a row inserted without the column gets it;
101+
- it **satisfies `required`**, so the caller is not asked for a value the model already guarantees;
102+
- it **seeds a new row in the UI**, so an editor opens on the default instead of on a blank.
103+
104+
::: info Normative
105+
A generator MUST apply the default when creating a new record and MUST NOT re-apply it to an existing one: a value the user cleared is a value the user chose, and re-defaulting it on the next edit would silently undo an intentional change. The default is a *starting value*, not a constraint — the user may replace it, and nothing revalidates a stored row against it. On a to-one relation the equivalent key is [`init`](/spec/relations), which names a seeded record.
106+
:::
107+
108+
A default is what makes a bulk affordance one action rather than several: a dialog that creates one line per working day is only useful if the line it creates already carries the usual values.
109+
88110
## Calculated fields
89111

90112
A field value can be derived instead of entered:

0 commit comments

Comments
 (0)