Repository navigation
Expand file tree
/
Copy pathFormPage.tsx
More file actions
2777 lines (2704 loc) · 134 KB
/
Copy pathFormPage.tsx
File metadata and controls
2777 lines (2704 loc) · 134 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* FormPage — single component that renders a FormView either as a public
* anonymous form (`/f/:slug` → backend `GET/POST /api/v1/forms/:slug`) or
* as an authed internal form (`/forms/:name` → `GET /api/v1/meta/view/:name`
* + `POST /api/v1/data/:object`).
*
* Both modes share the same renderer; the difference is only in how the
* spec is loaded, where submissions go, and — since objectui#4109 — what
* happens after a successful submit when the form view declares nothing:
* an internal submit lands on the record it just wrote, while the public
* path keeps the anonymous `thank-you` confirmation. See
* {@link resolveSubmitBehavior}. This is the same shape as Airtable Forms —
* the form view metadata is identical whether it is embedded publicly or
* used by logged-in operators.
*
* ## Create vs edit (objectui#4278)
*
* The internal route also serves EDIT, and which one it is comes from the URL:
* `ActionRunner.executeForm` forwards the record an action was fired from as
* `/forms/:name?recordId=<id>`. Until #4278 this route ignored that param
* entirely — it rendered empty inputs and its submit was an unconditional
* `POST` — so an "edit this record" action produced a blank form and then a
* DUPLICATE record. `?recordId=` now selects the whole read/write pair:
* `GET /data/:object/:id` to prefill, `PATCH /data/:object/:id` to save. See
* {@link readFormRecordTarget} for the create/edit/refuse decision and
* {@link readPrefill} for what wins when a `prefill_` param and a stored value
* name the same field.
*
* ## Which object that id belongs to (objectui#4292)
*
* An id alone does not say which object it names, so the read/write pair above
* resolves it against the FormView's own target — right when the action fired
* from a record of that object, silently wrong when it did not. `?recordObject=`
* now travels with the id and this route refuses when the two disagree; see
* {@link FORM_RECORD_OBJECT_PARAM} for why it can only ever refuse, and the
* guard in {@link loadInternalForm} for where it fires (before any `/data/`
* request, so a mismatch reads nothing and writes nothing).
*
* ## Where a declared `redirect` goes (objectui#4190)
*
* `submitBehavior: { kind: 'redirect' }` was consumed as a browser-level
* navigation on the authored string, which is why the card asked what that
* string even meant. objectstack#7496 ruled it: a RELATIVE in-app path, with
* `{{record.field}}` interpolation, URL-escaped when the redirect is built.
* So the destination is a route in this shell and it is navigated to with the
* router — a full-page navigation ignores the console mount and drops the
* submitter at the origin root — while an out-of-contract absolute is refused
* on screen instead of followed. See `submitRedirect.ts`.
*
* ## Conditional field visibility (objectui#5594)
*
* A FormView field may carry a CEL predicate saying WHEN it is visible —
* `visibleWhen` (ADR-0089). This renderer read it not at all before #5594, so such a field rendered unconditionally on both routes:
* fail-open and silent, with no diagnostic for the author.
*
* It is the SECOND form renderer in this repo, which is why the gap survived.
* objectui#2212 recorded this exact symptom and PR #2214 fixed it on the OTHER
* chain — `ModalForm` -> `resolveFormViewLayout` -> `@object-ui/plugin-form`
* `sectionFields.ts` -> `@object-ui/components` `renderers/form/form.tsx` —
* which this file is on at no point, and #2212's regression pin lives with
* that chain, so nothing in the suite could see this copy.
*
* The wiring is #2212's ruling applied verbatim, not a second semantics: see
* {@link isFieldVisible} for the engine, the bound scope, and what the fix
* deliberately does not change.
*
* ## The other three conditional-rule surfaces (objectui#5627)
*
* #5594 wired ONE of the four surfaces the sibling chain honours — the
* view-level field predicate. The other three were dropped in the same place
* and for the same reason: nothing downstream could read a key this file's
* payload types did not admit.
*
* - SECTION-level `visibleWhen` (ADR-0089). The section type is
* no longer this file's to widen — objectui#5596 replaced the hand copy with
* the shared `FormSectionSpec`, which has DECLARED these two keys ever since
* ("declaring a key is not honouring it", as that type's own docstring says
* while naming this card). What was missing here was the evaluation, and the
* render mapped every section unconditionally. See {@link isSectionVisible}.
* - OBJECT-level `visibleWhen` / `readonlyWhen` / `requiredWhen` (ADR-0036),
* authored on the object's field rather than on the form view. This file's
* own `ObjectFieldDef` admitted none of them, so `readonly` and `required`
* were whatever the static flags said. See {@link resolveRowState}, which
* resolves them through the SHARED `resolveFieldRuleState` rather than
* re-deriving what the three rules mean for a fourth time.
*
* Both halves are RENDERING rules: a hidden section's fields still submit their
* values, exactly as a hidden field's do (triage ruling, 2026-08-22, following
* #5594 and the plugin-form chain). Nothing in this file makes visibility a
* submit-payload rule, at either granularity.
*
* ## The one thing that IS a submit-payload rule (objectui#5883)
*
* A field whose declared `defaultValue` is an instruction the SERVER resolves
* per insert is left out of a create payload when the control is empty — see
* {@link omitServerOwnedBlanks}. That is not a visibility rule wearing a
* different hat: the key is withheld precisely so the producer supplies the
* value, which is the whole meaning of the declaration. It is the submit half
* of the fence {@link readPrefill} put on seeding for objectui#5727, and the
* sibling of `@object-ui/plugin-form`'s `omitServerResolvedDefaults`.
*
* ## One field layer, not two (objectui#10179, objectui#10177)
*
* The page shell above is this file's own; the FIELD layer is not. Each row
* renders the widget the shared resolver names for it — `resolveFormWidgetType`
* + `getLazyFieldWidget`, the ADR-0059 door — including the two axes a
* type-keyed switch cannot see: an authored `widget` (which wins over `type`
* when it names a registered widget, and otherwise degrades to the `type`
* renderer as the spec's `FieldSchema.widget` declares — objectui#10472)
* and arity (`select` + `multiple: true` is the multiselect widget). Until
* #10179 a hand-rolled `switch (field.type)` stood here that knew a subset of
* the declared types and rendered every other one as a text box, silently.
* See {@link resolveFieldWidgetKey} for the decision and {@link FieldInput} for
* the host half (ids, label association, required, uploads).
*/
import { Suspense, useContext, useEffect, useId, useMemo, useState, type FormEvent } from 'react';
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { toast } from 'sonner';
import {
CASCADE_OPTION_WIDGET_TYPES,
EXPANDABLE_FIELD_TYPES,
evalFieldPredicate,
isMissingForRequired,
isRuntimeDefault,
isServerOwnedValue,
resolveFieldRuleState,
type FieldRuleFaults,
type FieldRulePredicate,
} from '@object-ui/core';
import {
omitServerResolvedDefaults,
optionListDefault,
resolveSectionGroupReferences,
} from '@object-ui/plugin-form';
// ADR-0059's published door for a host that renders field widgets OUTSIDE the
// form renderer: `resolveFormWidgetType` + `getLazyFieldWidget` hand back the
// very component `@object-ui/fields` registers for the form, so a host built on
// this seam "can never drift behind the form surface" (that resolver's own
// docblock). `@object-ui/app-shell`'s `ActionParamDialog` is the other host on
// it. Since objectui#10179 EVERY row of this page goes through it — see
// {@link resolveFieldWidgetKey} and {@link FieldInput}.
import {
FIELD_WIDGET_LABELLING,
getLazyFieldWidget,
mapFieldTypeToFormType,
resolveFormWidgetType,
} from '@object-ui/fields';
import { SchemaRendererContext, usePredicateScope, type ApiFetch } from '@object-ui/react';
import { pickLocalized, useObjectTranslation, useSafeFieldLabel } from '@object-ui/i18n';
import type { FormFieldSpec, FormSectionSpec, FormViewSpec } from '@object-ui/app-shell';
import type { ObjectFormSection } from '@object-ui/types';
import { resolveSubmitRedirect } from './submitRedirect';
const API_BASE = (import.meta.env.VITE_SERVER_URL || '') + '/api/v1';
/** Resolved server payload for a public form. */
interface PublicFormPayload {
slug: string;
object: string;
label?: string;
form: FormViewBody;
objectSchema: ObjectSchemaPayload | null;
}
interface ObjectSchemaPayload {
name: string;
label?: string;
fields: Record<string, ObjectFieldDef>;
/**
* The object's declared field groups (ADR-0085 §5), carried so a form
* section may REFERENCE one instead of enumerating members (objectui#8641).
*
* Untyped on purpose: this key is never read HERE. It travels straight to
* `resolveSectionGroupReferences`, whose derivation
* (`deriveFieldGroupLayout`) owns what a `fieldGroups` entry may say — and
* `@objectstack/spec` owns THAT. Restating the entry shape in this app would
* put a second description of one contract in the place least likely to be
* updated when the contract moves.
*/
fieldGroups?: unknown;
}
interface ObjectFieldDef {
type: string;
label?: string;
/**
* Which declared `fieldGroups` entry this field belongs to (ADR-0085 §5).
*
* Membership is the ONLY input the group derivation needs per field, and
* this app never reads the key itself — see {@link ObjectSchemaPayload.fieldGroups}.
* Declared so the group half of the object schema is describable rather than
* smuggled through as an untyped bag (objectui#8641).
*/
group?: string;
required?: boolean;
defaultValue?: unknown;
maxLength?: number;
/**
* The upload configuration `@objectstack/spec` declares on a field and the
* shared `FileField` reads — `multiple`, `accept` (a list of MIME types or
* extensions) and `maxSize` (BYTES).
*
* Admitted here for the reason objectui#5627 states about the conditional
* rules two slots down: nothing downstream can read a key this file's payload
* types do not admit, so a `file` field rendered through the shared widget
* would have been a single-file, unfiltered, unbounded dropzone no matter
* what the object declared — the widget's defaults, not the author's. The
* server already serves all three (spec's field schema declares
* `multiple` / `accept` / `maxSize`); only this app's narrowed view of the
* payload dropped them.
*
* `multiple` is also the ARITY half of the widget decision: on a `select`
* it selects a DIFFERENT widget (the multiselect chip picker), which
* {@link resolveFieldWidgetKey} reads through the shared
* `mapFieldTypeToFormType` table rather than a local copy (objectui#10179).
*/
multiple?: boolean;
accept?: string[];
maxSize?: number;
/**
* The spec's field-level render hint (`FieldSchema.widget`) — the object
* field's own, read as the fallback for a form view that declares none
* (objectui#10177). Three widget keys (`object-ref`, `filter-condition`,
* `recipient-picker`) are reachable ONLY through this key.
*/
widget?: string;
options?: Array<{ value: string; label?: string }> | string[];
placeholder?: string;
helpText?: string;
/**
* The OBJECT-level conditional rules (ADR-0036), authored on the object's
* field rather than on a form view — a DIFFERENT slot from the view-level
* predicate {@link RenderableField.visibleWhen} carries (objectui#5627).
*
* The sibling chain keeps the two apart on purpose: `@object-ui/plugin-form`
* `sectionFields.ts` copies these three straight off the object field and
* routes the VIEW predicate into `visibleOn` "so the object rule is never
* clobbered", and `@object-ui/components` `renderers/form/form.tsx` then
* evaluates the two slots independently and ANDs them. This file admitted
* neither of them until #5627, so `buildSections` could not read what it was
* never handed: `readonly` was `override.readonly ?? false` and `required`
* was `override.required ?? def.required ?? false` — static, never
* conditional, on both routes including the anonymous `/f/:slug` one.
*
* Typed as `@object-ui/core`'s own {@link FieldRulePredicate} rather than
* re-spelled, because that is the parameter type of `resolveFieldRuleState`,
* the engine every one of these predicates is handed to. (The view-level slot
* derives its type from `FormFieldSpec` for the same reason, one layer up.)
*/
visibleWhen?: FieldRulePredicate;
readonlyWhen?: FieldRulePredicate;
requiredWhen?: FieldRulePredicate;
}
/** Visualization types the form renderer understands (FormViewSpec.type). */
const FORM_SPEC_TYPES = new Set(['simple', 'tabbed', 'wizard', 'split', 'drawer', 'modal']);
/**
* The form CONFIG plus the view identity that travels beside it (objectui#5596).
*
* {@link FormViewSpec} is the converged form contract and carries no `label`:
* `@objectstack/spec`'s `FormViewSchema` REJECTS that key outright
* (`unrecognized_keys`, measured against the installed 17.0.0) — a form config
* says `title`, not `label`. Until #5596 this file's hand copy declared `label`
* on the form type, which read as "a FormView may be labelled" and is not true.
*
* The value those reads actually find is the VIEW's identity label, and both
* bodies this renderer accepts carry it one way or another:
*
* - the `ExpandedViewItem` envelope (#2208) puts it beside `config`, and
* {@link resolveInternalForm} already reads it from there;
* - a FLATTENED runtime overlay has no envelope at all — the config and the
* identity share one object, which is exactly what the spec publishes as
* `VIEW_METADATA_MEMBERS.formOverlay` (`FormViewSchema` extended with
* `label` / `object` / `viewKind` / ...). On that branch `form === body`, so
* the label is reachable through the form variable.
*
* So the key is declared HERE, on the body this renderer unwraps, and not on the
* form contract shared with `packages/app-shell`. Narrowed to `string` because
* every read below assigns it into a `string` slot; the spec's own overlay types
* it `I18nLabel`, whose inline locale-map arm this renderer resolves for a field
* entry's copy ({@link buildSections}, objectui#13380) but not for this label.
*/
type FormViewBody = FormViewSpec & { label?: string };
/**
* Post-submit behaviour — DERIVED from the converged form contract, not
* restated (objectui#5596).
*
* This was a hand-written four-member union carrying the comment "Mirrors the
* spec FormView.submitBehavior union", which is the claim shape
* `scripts/check-spec-symbol-derivation.mjs` exists to catch: a mirror that
* nothing checks is one spec release from being a fork. Reading it back off
* {@link FormViewSpec} makes the mirror structural.
*
* `redirect.url` is still a plain string, because that is what the contract
* ships: the ruled shape (objectstack#7496) is a refinement ON a string, so the
* key arrives as the author wrote it. What it is ALLOWED to say is not restated
* here either — `resolveSubmitRedirect` asks the spec's own schema at the
* moment of use (`submitRedirect.ts`).
*/
type SubmitBehavior = NonNullable<FormViewSpec['submitBehavior']>;
/** Which surface is rendering the form — see {@link FormPageProps.mode}. */
export type FormPageMode = 'public' | 'internal';
/**
* The query param naming the record an internal form edits — the one
* `ActionRunner.executeForm` forwards (`/forms/:name?recordId=<id>`).
*
* ## Why the same spelling as the drawer's reserved param, deliberately
*
* `recordId` is ALREADY reserved in `@object-ui/app-shell`'s registry
* (`src/urlParams.ts` → `RECORD_DRAWER_PARAM`), where it opens a record-detail
* drawer over a list. That is not a collision to route around, and #4278 ruling
* point 3 asked for the relationship to be measured rather than assumed:
*
* - the two readers can never see one URL. React Router renders exactly one
* leaf per location, `/forms/:name` is a TOP-LEVEL route in `App.tsx`
* (sibling of `/apps/*`, where `ObjectView` — the drawer's only reader,
* `views/ObjectView.tsx`, the single `RECORD_DRAWER_PARAM` call site
* outside the registry itself — is mounted), and `InternalFormRoute` renders
* `DefaultHomeLayout` + this component and no list. Disjoint subtrees, so
* the same URL cannot carry both meanings at once;
* - and the MEANING is the same one either way — "the record this surface is
* about". A second spelling (`formRecordId`, …) for that fact would be the
* de-facto second contract AGENTS.md #0.1 forbids, and would make the
* already-reserved name look free to repurpose.
*
* So this is the registry's name, used as the registry defines it. It is a
* literal here rather than an import only because `@object-ui/app-shell`
* exports its package root alone — its `exports` map publishes `.` and
* `./styles.css`, nothing else — and that root does not re-export
* `./urlParams`, so `RECORD_DRAWER_PARAM` has no spelling a consumer can
* import. Retiring this literal means publishing the registry from that root,
* the way objectui#4280 collected `resolveHostAppSegment`. `FormPage.test.ts`
* pins the two spellings equal so they cannot drift apart in silence.
*/
export const FORM_RECORD_ID_PARAM = 'recordId';
/**
* The object the accompanying {@link FORM_RECORD_ID_PARAM} belongs to
* (objectui#4292) — `ActionRunner.executeForm` forwards the two together.
*
* ## Why an id needed an object at all
*
* `?recordId=` names an id and nothing else, so this route has to pick an
* object to resolve it against, and it picks the FormView's own target — the
* only one it knows. That is right whenever the action fired from a record OF
* that object, and until #4292 nothing checked that it had: an action whose
* `locations` put it on an Account but whose `target` is `showcase_task.edit`
* is publishable metadata, and where primary keys are per-table integers
* `GET /data/showcase_task/42` answers happily for the user who was looking at
* Account 42. The server cannot flag it either — it echoes the path's object
* back (`getData` returns `object: request.object`), so the response is
* self-consistent. #4278 shipped the read/write pair that turned that from a
* duplicate INSERT into a targeted UPDATE of the wrong record, which is what
* made the missing identity worth closing.
*
* ## An ASSERTION, never an override — the whole point
*
* This param cannot change which object the form edits; that comes from the
* view metadata and only from there. Its sole power is to make the form
* REFUSE. Reading it as a selector instead would let any hand-authored URL aim
* a form at an arbitrary object — the same hole, re-opened from the other side.
* (The registry's `formObject` is deliberately the other thing: it selects the
* object the record-form OVERLAY edits. Same `<param>Object` naming, opposite
* powers, separate surfaces.)
*
* Spelled as a literal here and in `ActionRunner` for the reason
* {@link FORM_RECORD_ID_PARAM} documents — `@object-ui/core` sits below this
* app and app-shell exports no `./urlParams`. `FormPage.test.ts` pins the two
* ends together by running the real producer and reading its URL back here,
* so a rename on either side fails rather than silently disarming the guard.
*/
export const FORM_RECORD_OBJECT_PARAM = 'recordObject';
/**
* What the URL says this internal form is FOR: creating a record, editing a
* named one, or nothing coherent.
*
* The third case is the point. #4278 ruling point 2 is fail-closed: an edit
* intent this route cannot honour must reach the error state, because silently
* falling back to create mode is the EXACT harm the card was filed about (an
* empty form whose submit inserts a duplicate). A present-but-blank
* `?recordId=` — which `ActionRunner` really can emit, since it appends the
* param for any `recordId != null` and an empty-string id passes that test —
* declares edit intent and names no record, so it refuses rather than degrades.
*/
export type FormRecordTarget =
| { kind: 'create' }
| { kind: 'edit'; recordId: string; recordObject: string | null }
| { kind: 'refuse'; reason: string };
/**
* Decide {@link FormRecordTarget} from the surface and the query string.
*
* PUBLIC mode never reads the param, and that is a contract, not an
* optimisation: `/f/:slug` is the anonymous surface, where the visitor
* controls the URL and the backend resolver deliberately exposes one
* submit-only endpoint. Honouring `?recordId=` there would turn a public form
* into an arbitrary-record reader and writer. The public path is unchanged by
* every part of #4278, and this line is where that holds — `recordObject`
* (#4292) is read on the same terms, i.e. not at all on that surface.
*
* `recordObject` is carried to the loader rather than judged here: the object
* it must agree with is the FormView's, which only the view metadata knows, so
* the comparison happens where that arrives ({@link loadInternalForm}). What
* this function decides is unchanged — create, edit, or refuse from the URL
* alone. A blank or whitespace-only `recordObject` is treated as ABSENT, not as
* a mismatch: it asserts nothing, and #4292 ruling point 2 tightens the guard
* only where identity information is actually present (a URL can always just
* omit the param, so refusing here would buy nothing and would break the
* hand-authored deep links the ruling preserves).
*/
export function readFormRecordTarget(
mode: FormPageMode,
search: URLSearchParams,
): FormRecordTarget {
if (mode !== 'internal') return { kind: 'create' };
const raw = search.get(FORM_RECORD_ID_PARAM);
// No id ⇒ create, whatever `recordObject` says: with no record named there is
// nothing for an object assertion to be about.
if (raw === null) return { kind: 'create' };
const recordId = raw.trim();
if (!recordId) {
return {
kind: 'refuse',
reason:
`This form was opened to edit a record (?${FORM_RECORD_ID_PARAM}=), but no record id was supplied. ` +
'Re-open it from the record, or drop the parameter to create a new one.',
};
}
const declaredObject = (search.get(FORM_RECORD_OBJECT_PARAM) ?? '').trim();
return { kind: 'edit', recordId, recordObject: declaredObject || null };
}
/**
* What the renderer actually does after a successful submit: every authorable
* {@link SubmitBehavior}, plus the one behaviour the PLATFORM supplies rather
* than the author.
*
* `created-record` is deliberately NOT a member of the spec's authorable union
* (`thank-you | redirect | continue | next-record` — a STRICT discriminated
* union in `@objectstack/spec`, so authoring `kind: 'created-record'` is
* rejected at publish time and always will be). Nothing ever parses it out of
* metadata: it exists only as the value {@link resolveSubmitBehavior} returns
* when an internal form declares nothing. That is what lets the platform
* default differ from every authorable kind WITHOUT widening the contract or
* teaching authors a second dialect for something they never write.
*
* Since objectui#4278 the internal route also EDITS, and this one value covers
* both writes: "land on the record this submit wrote" — the created one, or
* the one `?recordId=` named. It is one behaviour, so it keeps one name; a
* second `updated-record` kind would be two spellings of a single rule, and
* the name is #4109's rather than churned here because renaming it would
* restate a just-landed contract for cosmetics. The create/edit split lives
* where it belongs — in the id the handler navigates with, not in the union.
*/
type EffectiveSubmitBehavior = SubmitBehavior | { kind: 'created-record' };
/** Normalized field row used by the renderer. */
interface RenderableField {
name: string;
label: string;
type: string;
required: boolean;
readonly: boolean;
hidden: boolean;
/**
* Conditional visibility for this row, as authored on the FORM VIEW's field
* — the predicate {@link isFieldVisible} evaluates against the LIVE form
* values, as distinct from the static `hidden` flag above.
*
* The VIEW level, specifically: the object field's own `visibleWhen` is a
* separate rule that lives in {@link RenderableField.rules} and is ANDed with
* this one by {@link resolveRowState} (objectui#5627). Two layers may both
* condition one control, and either one hiding it is enough.
*
* Read from `visibleWhen` ONLY (objectui#12654). ADR-0089 renamed the key,
* and `@objectstack/spec` 18 retires the old `visibleOn` spelling as a
* `retiredKey` tombstone (objectstack#23543 F4): every parsing door refuses
* it by name, and a stored row written with it is rehydrated to
* `visibleWhen` before it is served. A raw view still carrying `visibleOn`
* is therefore an authoring mistake the spec reports, and this reader does
* not fold it back — a renderer-side `??` would hide that mistake. The
* runtime form chain reads the same single key
* (`@object-ui/plugin-form` `sectionFields.ts`).
*
* The TYPE is derived from the authoring surface rather than restated:
* re-spelling `string | { dialect?, source }` here would be a third
* description of one contract, which is the exact class objectui#5542 closed
* in this file.
*/
visibleWhen?: FormFieldSpec['visibleWhen'];
/**
* The OBJECT-level rules (ADR-0036) copied off {@link ObjectFieldDef} —
* `visibleWhen`, `readonlyWhen`, `requiredWhen` (objectui#5627).
*
* Carried as a GROUP rather than as three sibling keys because the group IS
* `resolveFieldRuleState`'s first parameter: {@link resolveRowState} hands
* this object over whole, so there is no per-key re-assembly step for a
* fourth consumer-side copy of the rule semantics to hide in. Nesting also
* settles the one genuine ambiguity in this row type — `visibleWhen` one
* level up is the VIEW's predicate, `rules.visibleWhen` is the OBJECT's, and
* the sibling chain's runtime `FormField` happens to spell that same pair the
* other way round (`visibleWhen` = object, `visibleOn` = view). A reader of
* either file can tell which layer a predicate came from without knowing the
* other file's convention.
*
* Carried, not evaluated, for the reason the view-level slot is: the verdict
* depends on the live values, and these rows are memoized on the loaded spec.
*/
rules?: {
visibleWhen?: FieldRulePredicate;
readonlyWhen?: FieldRulePredicate;
requiredWhen?: FieldRulePredicate;
};
placeholder?: string;
helpText?: string;
defaultValue?: unknown;
options?: Array<{ value: string; label: string }>;
maxLength?: number;
/**
* The upload configuration, copied straight off the object field — see
* {@link ObjectFieldDef.multiple} — and handed on to the shared widget whole
* rather than re-interpreted here. `multiple` is the EFFECTIVE one (the form
* view's, else the object's), because it also decides WHICH widget renders.
*/
multiple?: boolean;
accept?: string[];
maxSize?: number;
/**
* The authored render hint — the form view field's `widget`, else the object
* field's (objectui#10177). Same precedence as the sibling chain
* (`sectionFields.ts` copies `fd.widget` over the object field; `form.tsx`
* resolves `f?.widget || f?.field?.widget || f?.type`).
*/
widget?: string;
/**
* The object field exactly as the server served it — every key, not only the
* ones {@link ObjectFieldDef} names — so the widget handed this row finds
* what it reads off its metadata (a lookup's `reference`, a currency's
* `currency`, a code editor's `language`). See {@link widgetFieldOf}.
* Absent on a row built without an object field behind it. Typed as the
* slice this file names; at runtime it is the whole served object.
*/
meta?: ObjectFieldDef;
colSpan: 1 | 2 | 3 | 4;
}
interface RenderableSection {
/**
* The section's STABLE authored name (objectui#8813).
*
* Carried for ONE reason: it is the only member of this row that may appear
* in a translation key. The convention is
* `{ns}.objects.{objectName}._sections.{name}.label`, resolved by
* `useObjectLabel().sectionLabel` — so with `name` dropped at build time the
* key could not be CONSTRUCTED at the render site, whatever the renderer
* did there. That is why carrying it is a precondition of the section half
* of #8813 rather than a tidy-up that could follow it.
*
* ⛔ The authored `label` is never the key, not even as a fallback guess:
* `packages/plugin-form/src/__tests__/sectionLabelI18n.test.tsx` pins that
* for the sibling renderer, and that pin exists because the two halves of
* the form renderer had drifted apart once already.
*
* Optional because the authoring surface makes it optional
* ({@link FormSectionSpec}) — a section may be written with a heading and no
* name, and such a section simply has no key. A group-REFERENCED section
* (`{ group: 'parties' }`) arrives here already resolved, carrying the
* group's key as its `name`, so it is translatable on the same convention.
*/
name?: string;
label?: string;
/**
* The section's description, as served (objectui#12333). On the signed-out
* `/f/:slug` path the console holds no app bundle (objectui#12034), so the
* server localizes it under `Accept-Language` (objectstack-ai/objectstack#23497)
* and the renderer draws it as it arrives, the way `ObjectForm` draws its own.
*/
description?: string;
columns: 1 | 2 | 3 | 4;
collapsible: boolean;
collapsed: boolean;
/**
* Conditional visibility for the whole section (ADR-0089, objectui#5627),
* read from `visibleWhen` ONLY when the row is built (objectui#12654).
*
* The same key and the same reason as the field row one type up: spec 18
* retires the section's `visibleOn` spelling, so a served FormView carries
* only `visibleWhen`, and a raw view still writing the old key is refused
* by the spec rather than folded here. The shared machinery this file
* imports is the ENGINE — `evalFieldPredicate`, via
* {@link isSectionVisible} — which is the half that decides anything.
*
* Type derived from the shared authoring surface (objectui#5596's
* {@link FormSectionSpec}) rather than restated, exactly as the field row
* derives its own from `FormFieldSpec`.
*/
visibleWhen?: FormSectionSpec['visibleWhen'];
/**
* The fault direction of {@link visibleWhen} (objectui#13055), carried off
* the resolved section: `'hidden'` when the predicate is a field group's
* (`{ group }` reference), which `@objectstack/spec` declares fail-closed.
* An authored section's own predicate carries none and faults open. See
* `ObjectFormSection.visibleWhenFault`.
*/
visibleWhenFault?: ObjectFormSection['visibleWhenFault'];
fields: RenderableField[];
}
// ─── Helpers ─────────────────────────────────────────────────────────
/** Coerce a `columns` literal into a numeric 1..4. */
export function normalizeColumns(c: unknown): 1 | 2 | 3 | 4 {
const n = typeof c === 'string' ? parseInt(c, 10) : (c as number);
if (n === 1 || n === 2 || n === 3 || n === 4) return n;
return 2;
}
/** Normalize field options from various Object schema shapes into `{value,label}`. */
export function normalizeOptions(opts: unknown): Array<{ value: string; label: string }> | undefined {
if (!Array.isArray(opts)) return undefined;
return opts.map((o) => {
if (typeof o === 'string') return { value: o, label: o };
if (o && typeof o === 'object') {
const v = String((o as any).value ?? (o as any).id ?? '');
const l = String((o as any).label ?? (o as any).name ?? v);
return { value: v, label: l };
}
return { value: String(o), label: String(o) };
});
}
/**
* What `resolveFormWidgetType` answers for a spelling nothing registers — its
* documented fallback ("anything unknown falls back to `text`"). Read by
* {@link namesRegisteredWidget} alone.
*/
const UNKNOWN_SPELLING_WIDGET = 'text';
/**
* Does an authored `widget` spelling name a widget the shared registry holds
* (objectui#10472)?
*
* The spec's `FieldSchema.widget` declares that the override "names a
* registered field component" and "Degrades to the `type` renderer when
* unregistered". The `widget` leg of {@link resolveFieldWidgetKey} used to
* return `resolveFormWidgetType(widget)` unconditionally, and that resolver
* answers a spelling nothing registers with its `text` fallback — so a
* `select` field carrying `widget: 'no_such_widget'` rendered a free-text box
* instead of its select.
*
* ⛔ No list of widgets lives here. The question goes to the SAME resolver the
* row renders through (`getLazyFieldWidget` mounts what it names), and is read
* for that one documented answer: a spelling it answers with `text`, when the
* author did not write `text`, named nothing. Everything else it knows keeps
* resolving as before — a registered key, a retired spelling (whose tombstone
* still refuses visibly) and an alias of a registered key (`secret` →
* `password`).
*/
function namesRegisteredWidget(widget: string): boolean {
return resolveFormWidgetType(widget) !== UNKNOWN_SPELLING_WIDGET || widget === UNKNOWN_SPELLING_WIDGET;
}
/**
* The registered widget key a row renders (objectui#10179, objectui#10177).
*
* ⛔ No mapping lives here. Every step is the shared chain's own answer, in the
* order the sibling renderer applies them:
*
* 1. an authored `widget` that names a REGISTERED widget wins over `type`
* outright, un-arity'd — `form.tsx` resolves
* `f?.widget || f?.field?.widget || f?.type`, where only the `type` leg was
* produced by `mapFieldTypeToFormType(type, { multiple })`. One that names
* nothing takes the next two steps instead (objectui#10472), because the
* spec's `FieldSchema.widget` declares that it "Degrades to the `type`
* renderer when unregistered" — see {@link namesRegisteredWidget};
* 2. otherwise ARITY: `mapFieldTypeToFormType` is asked for the multi-value
* answer, and it is taken only where the shared table says the arity MOVES
* the widget (`select` + `multiple` → `multiselect`). Every other
* multi-capable type (`lookup`, `file`, `image`, `user`) renders both
* arities inside one widget, so it keeps the key the resolver gives the
* bare type — the membership of that table is `@object-ui/fields`'s, not
* restated here;
* 3. `resolveFormWidgetType` for the rest — aliases, retired spellings (a
* tombstone that refuses visibly) and the documented `text` fallback for
* a spelling nothing registers.
*/
function resolveFieldWidgetKey(field: {
type: string;
widget?: string;
multiple?: boolean;
}): string {
if (field.widget && namesRegisteredWidget(field.widget)) {
return resolveFormWidgetType(field.widget);
}
if (field.multiple) {
const multi = mapFieldTypeToFormType(field.type, { multiple: true });
if (multi !== mapFieldTypeToFormType(field.type)) {
return resolveFormWidgetType(multi.replace(/^field:/, ''));
}
}
return resolveFormWidgetType(field.type);
}
/**
* How a row's visible label reaches the widget with this key — the widget's
* own `labelling` declaration (`FIELD_WIDGET_LABELLING`, objectui#3961 /
* #4857), never a guess made here:
*
* - `'control'` — the widget renders a labelable element carrying the host
* id, so a plain `<label for>` names it;
* - `'group'` — a composite or a non-labelable control (a radio group, a chip
* row, a dropzone); the label publishes an `id` and the WIDGET answers with
* `aria-labelledby`;
* - `'display'` — a pure display with no control at all; the HOST wraps it in
* a named group, as `form.tsx` does.
*
* A key the table does not hold (a retired spelling's tombstone) is
* `'control'`, the same default every host reads for an absent declaration.
*/
function widgetLabelling(widgetKey: string): 'control' | 'group' | 'display' {
return (FIELD_WIDGET_LABELLING as Record<string, 'control' | 'group' | 'display' | undefined>)[widgetKey]
?? 'control';
}
/**
* Merge a FormView's section/field overrides with the target object's
* field definitions to produce concrete rows the renderer can draw.
* Field-level FormField overrides take precedence over object defaults.
*
* ## A field entry's copy is collapsed to `language` here (objectui#13380)
*
* `@objectstack/spec`'s `FormFieldBaseSchema` types an entry's `label`,
* `placeholder` and `helpText` as `I18nLabel`: a string, or an inline
* per-locale map such as `{ en, 'zh-CN' }`. The public resolver serves the map
* unchanged, and every row slot below is a `string` that reaches JSX — the
* label as `fieldLabel`'s fallback, which hands an unmatched fallback back
* untouched. So one map on a label or help line rendered an object as a React
* child and blanked the page for every visitor, on both routes; on a
* placeholder it read `[object Object]`.
*
* The map is reduced with `pickLocalized`, the resolver
* `useActionTextLocalizer` collapses an action's `I18nLabel` copy with, BEFORE
* it becomes the row: a row then carries one string, and that string is what
* the bundle lookup at the render site falls back to — the same order the
* action hook uses. `FormFieldSpec` narrows these keys to `string`, which
* describes what this builder EMITS, not what the wire may carry, so the read
* is not gated on the declared type.
*
* `language` is the visitor's (`useObjectTranslation().language`). Left out,
* `pickLocalized` reads `en`, so a caller that has no language still gets a
* string.
*/
export function buildSections(
form: FormViewSpec,
objectSchema: ObjectSchemaPayload | null,
language?: string,
): RenderableSection[] {
const objFields = objectSchema?.fields ?? {};
// An absent key stays absent: `pickLocalized` spells a miss `''`, and an
// empty placeholder or help line is not the same row as none.
const localized = (value: unknown): string | undefined =>
value == null ? undefined : pickLocalized(value, language);
/**
* A section may declare its members EITHER way (objectui#8641): enumerate
* `fields`, or point `group` at one of the object's declared `fieldGroups`
* (`@objectstack/spec` 17.3.0, objectstack#13855, ADR-0085 §5). The loop
* below reads `sec.fields ?? []` and `sec.label`, and a `{ group }` section
* carries neither — measured in the DOM on both routes before this call
* existed: an empty bordered card, no heading, zero inputs, no diagnostic.
*
* ⛔ Nothing about the assembly is decided here. Declared order, the
* empty-group drop, the ungrouped trailing bucket and the collapse /
* `visibleWhen` passthrough all come from `deriveFieldGroupLayout` through
* `@object-ui/plugin-form`'s ONE adapter onto the section shape — the same
* code path `ObjectForm` resolves through, published for this call site
* (objectui#7051's standing constraint, and the reason this is an import
* rather than a second reader of the derivation). A group authored by
* reference renders the same section in this app and in the plugin because
* one of them IS the other's code path.
*
* `formType` is forwarded so a shape `@objectstack/spec` REFUSES gets the
* same answer here as there: `group` on a `formType: 'wizard'` section
* renders nothing and says why, rather than this renderer honouring what the
* spec door declines to accept.
*
* `resolvable` is left at its default. This builder only ever runs after the
* load settled, so a null `objectSchema` means the object metadata is
* genuinely absent — a failure the load path owns — and reporting a dangling
* group reference for it would be a second, wrong diagnosis of one failure.
*/
const authored = form.sections ?? form.groups ?? [];
const sections = (resolveSectionGroupReferences(
// Two packages describing ONE authored document: `FormSectionSpec` is the
// app-shell authoring type this app reads, `ObjectFormSection` the plugin's
// name for the same section. The parameter type is taken FROM the published
// signature rather than restated, so a change to it lands here as a compile
// error instead of a silent mismatch.
authored as unknown as NonNullable<Parameters<typeof resolveSectionGroupReferences>[0]>,
{
objectName: objectSchema?.name ?? '',
formType: form.type,
objectDef: objectSchema,
},
) ?? []) as unknown as Array<FormSectionSpec & Pick<ObjectFormSection, 'visibleWhenFault'>>;
return sections.map((sec) => {
const cols = normalizeColumns(sec.columns);
const fields: RenderableField[] = [];
for (const entry of sec.fields ?? []) {
const override: FormFieldSpec =
typeof entry === 'string' ? { field: entry } : { ...entry };
const def: ObjectFieldDef =
objFields[override.field] ?? ({ type: 'text' } as ObjectFieldDef);
fields.push({
name: override.field,
// objectui#13380 — the three `I18nLabel` keys, collapsed to the
// visitor's language before they reach a `string` slot.
label: localized(override.label ?? def.label) ?? override.field,
type: def.type ?? 'text',
required: override.required ?? def.required ?? false,
readonly: override.readonly ?? false,
hidden: override.hidden ?? false,
// The one spelling — see `RenderableField.visibleWhen`. Carried, not
// evaluated: the verdict depends on the live form values, which change
// per keystroke, while these rows are memoized on the loaded spec.
visibleWhen: override.visibleWhen,
// The OBJECT's own rules (ADR-0036), off the object field and NOT
// merged with the view predicate above: two layers, two slots, ANDed
// at render by `resolveRowState` (objectui#5627). A `??` here would be
// the collapse the sibling chain avoids on purpose — a view predicate
// would then clobber the object's rule instead of narrowing it.
rules: {
visibleWhen: def.visibleWhen,
readonlyWhen: def.readonlyWhen,
requiredWhen: def.requiredWhen,
},
placeholder: localized(override.placeholder ?? def.placeholder),
helpText: localized(override.helpText ?? def.helpText),
defaultValue: def.defaultValue,
options: normalizeOptions(def.options),
// The FORM's ceiling wins over the object's, exactly like every
// sibling key above. This one key read `def` alone, so a tighter
// per-form limit — a short public intake form over a generously
// sized column — was discarded with no diagnostic, and the docstring
// promising overrides win was false for it (objectui#5595). The
// override can only NARROW what the author sees at the input; the
// object's storage ceiling still decides at submit time.
maxLength: override.maxLength ?? def.maxLength,
// The object's upload configuration. `accept` / `maxSize` read `def`
// alone: the FormView field override (`FormFieldSpec`) declares
// neither. `multiple` IS declared there, and it is the arity half of
// the widget decision, so the override wins as for every sibling key
// above — the precedence `sectionFields.ts` applies (objectui#10179).
multiple: override.multiple ?? def.multiple,
accept: def.accept,
maxSize: def.maxSize,
// objectui#10177 — the authored render hint, view over object.
widget: override.widget ?? def.widget,
colSpan: override.colSpan ?? 1,
// Carried whole for the widget — see `RenderableField.meta`. Only the
// served object field, never a synthesized stand-in: the `text`
// fallback above describes a missing definition, not metadata.
meta: objFields[override.field],
});
}
return {
// objectui#8813 — the copy the render site's translation key is built
// from. Before it, this builder read `sec.label` and dropped `sec.name`
// on the floor, and the public form `/f/:slug` rendered every section
// heading in the authoring language no matter what the app bundle
// carried. See `RenderableSection.name`.
name: sec.name,
label: sec.label,
description: sec.description,
columns: cols,
collapsible: !!sec.collapsible,
collapsed: !!sec.collapsed,
// The one spelling, as on the field row — see
// `RenderableSection.visibleWhen` (objectui#5627, objectui#12654).
visibleWhen: sec.visibleWhen,
visibleWhenFault: sec.visibleWhenFault,
fields,
};
});
}
/**
* Is this row on screen, given the form's current state?
*
* Two independent reasons a field is not rendered, answered in ONE place so
* "is this field visible" has a single reader:
*
* 1. `hidden: true` — the static flag. Unconditional.
* 2. `visibleWhen` — the conditional predicate (ADR-0089), evaluated against
* the live form values on every render.
*
* The predicate is routed through the CANONICAL engine — `evalFieldPredicate`
* (`@object-ui/core`, `evaluator/fieldRules.ts`) — which is objectui#2212's
* ruling applied verbatim rather than a second predicate semantics invented
* for this renderer. Two form renderers disagreeing about what `visibleWhen`
* MEANS would be a worse defect than one renderer ignoring it. So the engine,
* the accepted wire shapes (bare CEL string and `{ dialect, source }`), the
* bound scope and the failure behaviour are the shared ones by construction,
* not by agreement.
*
* Scope: `record.*` is the LIVE values — what the inputs currently hold, not
* what was loaded — so a predicate re-decides as the user types, which is the
* whole point of a conditional field. `previous.*` is the stored record an
* edit form started from (objectui#4278), unbound on a create form. That is
* the same pair `form.tsx` binds on the sibling chain.
*
* Fail-open (`fallback: true`) is deliberate and shared: a predicate that
* cannot be evaluated must not HIDE a field, because a hidden field is one the
* submitter can neither fill in nor see is missing. Open does not mean silent
* — `evalFieldPredicate` warns once per predicate text, naming the field.
*
* ## What this deliberately does NOT do
*
* It does not strip the VALUE of a field it hides. `values` still carries
* whatever {@link readPrefill} seeded and `handleSubmit` still submits it —
* exactly what a statically `hidden: true` field has always done here, and
* what the plugin-form chain does (#2212's fix returns `null` at render and
* clears stale ERRORS, never values). Conditional visibility is a rendering
* rule in both renderers; making it a submit-payload rule would be a new
* contract, decided once for both, not invented here in the second one.
*/
export function isFieldVisible(
field: RenderableField,
values: Record<string, unknown>,
previous?: Record<string, unknown> | null,
predicateScope?: Record<string, unknown>,
): boolean {
if (field.hidden) return false;
return evalFieldPredicate(field.visibleWhen, values, true, previous ?? undefined, predicateScope, {
// Named for the one key this row reads (ADR-0089, objectui#12654).
context: `visibleWhen of field '${field.name}'`,
});
}
/**
* Is this SECTION on screen, given the form's current state? (objectui#5627)
*
* The section-granularity twin of {@link isFieldVisible}, and deliberately the
* same three things: the one-key read (done once, at build time —
* `RenderableSection.visibleWhen`), the canonical ENGINE
* (`evalFieldPredicate`), and fail-OPEN with a one-time warning. A section that
* cannot be evaluated must not vanish, for the field-level reason multiplied by
* however many controls it holds: a section nobody can see is one the submitter
* can neither fill in nor notice is missing.
*
* Scope is the same pair the field predicate binds — live `record.*`, stored
* `previous.*` — so an author writes ONE dialect for both granularities, and
* `SECTION.visibleWhen` and `FIELD.visibleWhen` cannot disagree about what
* `record.status` refers to.
*
* ## Rendering rule, ruled (triage first-touch, 2026-08-22)
*
* > Section-level visibility is a rendering rule — a hidden section's fields
* > still submit, matching the field-level answer #5594 deliberately kept and
* > the plugin-form chain.
*
* So this decides what is DRAWN and nothing else: `values` still carries what
* {@link readPrefill} seeded and `handleSubmit` still submits it, exactly as a
* field hidden by its own predicate has done here since #5594.
*/
export function isSectionVisible(
section: RenderableSection,
values: Record<string, unknown>,
previous?: Record<string, unknown> | null,
predicateScope?: Record<string, unknown>,
): boolean {
// A field group's predicate is fail-CLOSED (objectui#13055): one that cannot
// be evaluated hides the section, and the warning names `false` as the
// default taken. Every other section keeps the fail-open answer above.
if (section.visibleWhenFault === 'hidden') {
if (section.visibleWhen == null) return true;
return evalFieldPredicate(section.visibleWhen, values, false, previous ?? undefined, predicateScope, {
context: `visibleWhen of field group section '${section.label ?? '(unlabelled)'}' — fail-closed, the section is hidden`,
});
}
return evalFieldPredicate(section.visibleWhen, values, true, previous ?? undefined, predicateScope, {
// The locator is the heading an author can actually find in their own
// metadata; an unlabelled section says so rather than printing
// `undefined`. Sections DO carry a `name` since objectui#8813, and this
// deliberately keeps naming the heading: a warning is read by the person
// looking at the screen, where the heading is what they see, and the
// wording is pinned by `FormPage.conditionalRules.test.tsx`.
context: `visibleWhen of section '${section.label ?? '(unlabelled)'}'`,
});
}
/**