Repository navigation
Commit 6303e74
fix(fields): a refused location draft blocks the record form's save (#32224)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} -->
_Requested by **Irene** · [project
thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67xSyNNRkJL7R2XBYfyfNzGZE)_
Fixes #32139
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:位置字段里输入的不是坐标(如 `Shenzhen
深圳`)时,表单现在把它当作该字段的校验错误,阻止保存,并在字段下用当前语言显示原因;不再静默保存。
- **为什么改**:之前控件拒收了这段文字,但表单不知道,点「更新」照样成功;用户先清空再输入时,原有位置被写成
`null`,提示却是保存成功。
- **风险与回滚**:只影响位置字段输错时的提交;合法坐标与故意清空照旧保存。回滚即还原两个源文件。
-
**先看**:`ui/packages/fields/src/widgets/LocationField.tsx`(上报拒收)、`ui/packages/components/src/renderers/form/form.tsx`(把
`location` 加入上报白名单)、`ObjectForm.locationRefusal.test.tsx`(编辑表单端到端)。
- **两分钟验证**:`pnpm --dir ui exec vitest run
packages/plugin-form/src/ObjectForm.locationRefusal.test.tsx`,预期 11
个全绿;或在 showcase 编辑任一 Account,Headquarters 输入 `Shenzhen 深圳` 点
Update,预期字段下出现红字、对话框不关闭。
- **需要你做的**:无,等席位评审后落地。
## What changes
- `LocationField` reports its refusal through `onInvalidInputChange`,
the channel the date picker already uses for text it cannot read
(objectstack#27483). It reports when the refusal message changes,
withdraws it when the refusal clears, when the field turns readonly, and
on unmount.
- The record-form validation seam is
`INVALID_INPUT_REPORTING_WIDGET_TYPES` in
`ui/packages/components/src/renderers/form/form.tsx`. Adding `location`
to it hands the widget the callback, and the form's existing
`invalidInput` validator turns the report into the field's error, which
blocks submit the way a missing required value does. No new validator,
no new locale key: the message is the widget's existing translated
refusal sentence (`fields.location.refusedFormat` / `refusedRange` /
`refusedResidue*`, present in every pack).
- No double display: the widget keeps drawing its own line until the
host's `error` carries the same sentence, then leaves it to the form's
`FormMessage`, so the reason never blinks out between the keystroke and
the asynchronous validation. Hosts that do not pass the callback (inline
edit through `FieldEditWidget`) keep the widget's own line exactly as
before.
- Clearing the box on purpose still emits `null` and saves it; a valid
pair still emits and saves.
## Tests
- New top-level describe in
`ui/packages/plugin-form/src/ObjectForm.locationRefusal.test.tsx`,
driving a real edit `ObjectForm` with `userEvent` (typing, then a click
on the submit button): non-coordinate text typed after clearing and
typed over the selected value both refuse Update with `update` never
called, `aria-invalid="true"`, the sentence in the form's own error line
and shown once; the zh-CN reader sees the Chinese sentence; a valid pair
saves; a deliberate clear saves `null`; correcting a refused draft
withdraws the error and saves.
- New top-level describe in
`ui/packages/fields/src/__tests__/LocationField.refusalDiagnostic.test.tsx`
for the widget side: report, withdraw on clear and on a valid pair, once
per message change, withdraw on unmount, own line until the host shows
the sentence, own line kept without the channel.
- Existing pins changed (deviation, named for review): the create-mode
pins in `ObjectForm.locationRange`, `ObjectForm.locationRefusal`,
`ObjectForm.locationResidue` and `ObjectForm.locationStoredRange`
asserted that a refused coordinate still let the create go through
(`create` called, `place` absent). That half is exactly what this card
reverses, so each now asserts the stronger reading: nothing is written
at all and the field carries the refusal. Every "never stored"
assertion, every announcement assertion and every pass-through assertion
is unchanged. The stored-range pin still proves the refusal is the
widget's and not the `location` rule's: the field error is the widget's
`Not saved:` sentence, never the rule's `Invalid location:`.
## Acceptance notes
- **Second observation on the card (not fixed here):** a no-change edit
sends the whole record. That is `dirtyEditPayload` in
`ui/packages/plugin-form/src/sanitize.ts` by design (objectui#10156): an
EMPTY diff sends the full sanitized payload, so a save with nothing
changed stays a real request with the OCC guard and a server record for
`onSuccess`. The card's typed-over case is that path: the refusal left
nothing changed. A whole record sent TOGETHER with a real change (`hq:
null` beside every other field, as the card reports) would mean the
loaded-record snapshot did not apply on the host the QA run used; that
is not measured here.
- The QA route that wrote `null` is reproduced by clearing the box
first, which emits a legitimate `null` before the refused text is typed.
The other route (typing over the selected value) left the old value
standing and still reported success. Both are now refused.
## Verification
<details><summary>Repro on origin/main 8523ef9 (new pins, before the
fix)</summary>
```
× non-coordinate text cleared first, then typed refuses the save and writes nothing
expected "vi.fn()" to not be called at all, but actually been called 1 times ("place": null)
× non-coordinate text typed over the selected value refuses the save and writes nothing
expected "vi.fn()" to not be called at all, but actually been called 1 times ("place": { lat: 22.54, lng: 114.05 })
× the refusal is translated: a zh-CN reader sees the field error in Chinese ("place": null)
× correcting a refused draft withdraws the error and saves the pair ("place": null)
Tests 4 failed | 7 passed (11)
```
</details>
<details><summary>After the fix</summary>
Head `21e59a53` (fix `d39e14b9` + changeset `da15605a` + merge of
`origin/main` `171cf6d9`, which touched `packages/spec` only).
```
pnpm --dir ui exec vitest run packages/plugin-form/src/ObjectForm.location packages/fields/src/__tests__/LocationField packages/components/src/renderers/form/__tests__/form-invalid-input-refuses-submit-27483.test.tsx packages/fields/src/__tests__/date-picker-invalid-text-blocks-submit-27483.test.tsx
Test Files 14 passed (14)
Tests 219 passed (219)
```
```
pnpm --filter @object-ui/fields run type-check :: exit 0
pnpm --filter @object-ui/components run type-check :: exit 0
pnpm --filter @object-ui/plugin-form run type-check :: exit 0
pnpm --dir ui exec vitest run packages/fields/ packages/components/ packages/plugin-form/
Test Files 1006 passed | 2 skipped (1008)
Tests 11628 passed | 32 skipped (11660)
```
</details>
<details><summary>Reverse verification (fix committed first, then
reverted on disk, then restored from HEAD)</summary>
- Both source files restored from origin/main: 19 of 69 pins red across
the five location files: the four refusal pins of the new edit-form
describe (its two preservation pins, valid pair saves and deliberate
clear writes `null`, stay green as they should), five of the six new
widget pins (the sixth, own line kept without the channel, is a
preservation pin), and the ten create-mode pins whose submit is now
refused. Restored with `git checkout HEAD --`, `git diff HEAD` empty.
- Only the form seam removed (`location` dropped from
`INVALID_INPUT_REPORTING_WIDGET_TYPES` via
`scripts/ablation-replace.mjs`): 6 of 11 red in
`ObjectForm.locationRefusal.test.tsx`; restored blob identical to HEAD.
</details>
<details><summary>Gates</summary>
All 36 commands `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derives for this diff exit 0, plus `node
scripts/check-sdui-manifest.mjs` (derived) and `pnpm --dir ui run
check:spec-symbols` and `pnpm --dir ui run check:new-line-citations`
(not derived), both exit 0. `pnpm check:type-check-debt` needed three
runs: a 300 s local timeout and a verify-lock queue behind this card's
own test run were NOT MEASURED, the third run on `21e59a53` exited 0.
`--ran` reconciliation: 36 derived, 36 run, 0 NOT-MEASURED, 0 UNRUN.
Every other CI family is read from this PR's check-runs.
</details>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent ca2a2e9 commit 6303e74
8 files changed
Lines changed: 353 additions & 29 deletions
File tree
- .changeset
- ui/packages
- components/src/renderers/form
- fields/src
- __tests__
- widgets
- plugin-form/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1377 | 1377 | | |
1378 | 1378 | | |
1379 | 1379 | | |
1380 | | - | |
1381 | | - | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
1382 | 1386 | | |
1383 | 1387 | | |
1384 | 1388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
443 | 451 | | |
444 | 452 | | |
445 | 453 | | |
| |||
518 | 526 | | |
519 | 527 | | |
520 | 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 | + | |
521 | 558 | | |
522 | 559 | | |
523 | 560 | | |
524 | 561 | | |
525 | 562 | | |
526 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
527 | 573 | | |
528 | 574 | | |
529 | 575 | | |
| |||
592 | 638 | | |
593 | 639 | | |
594 | 640 | | |
595 | | - | |
| 641 | + | |
596 | 642 | | |
597 | 643 | | |
598 | 644 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
79 | 88 | | |
80 | 89 | | |
81 | 90 | | |
| |||
90 | 99 | | |
91 | 100 | | |
92 | 101 | | |
93 | | - | |
94 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
95 | 112 | | |
96 | 113 | | |
97 | 114 | | |
| |||
104 | 121 | | |
105 | 122 | | |
106 | 123 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
113 | 132 | | |
114 | 133 | | |
115 | 134 | | |
116 | 135 | | |
117 | | - | |
118 | | - | |
| 136 | + | |
| 137 | + | |
119 | 138 | | |
120 | 139 | | |
121 | 140 | | |
122 | 141 | | |
123 | 142 | | |
124 | | - | |
| 143 | + | |
125 | 144 | | |
126 | 145 | | |
127 | 146 | | |
| |||
0 commit comments