Skip to content

[console] Conditional required (requiredWhen): submit-time validation uses the mount-time snapshot — star correctly disappears, submit still blocked with zero POST #4161

Description

@baozhoutao

Environment

@objectstack/*@17.0.0-rc.6, Console record create dialog.

Summary

The create form's submit-time required validation appears to be snapshotted when the dialog mounts. A requiredWhen predicate that later flips to FALSE updates the display layer (the required star disappears as expected) but not the validation layer: submit is still refused with " 不能为空", and no POST is issued at all.

Minimal repro (generic shape)

Object with a select field A (no defaultValue) and a lookup field B:

B: Field.lookup({
  requiredWhen: P`!(has(record.A) && record.A == "x")`,
})
  1. Open the create dialog → B shows the required star (A key absent ⇒ predicate TRUE — expected).
  2. Pick A = "x"B's required star disappears (live re-evaluation works on the display layer).
  3. Click Create → error "B 不能为空", and no POST /api/v1/data/<object> request is issued.
  4. Control: open an edit dialog on an existing record whose A is already "x"B unstared, save PATCHes 200. The only difference from step 3 is whether A had a value at mount time — which is what implicates a mount-time snapshot.

Assertions observed

  • After step 2: B's label contains no *, no required marker in the field container.
  • After step 3: inline error "B 不能为空" appears; network shows zero create POSTs.
  • Server-side control (only the client is affected): direct POST /api/v1/data/<object> with {"A":"x"} and no B201; with A at another value and no B400 VALIDATION_FAILED. Server requiredWhen semantics are correct.

Expected

Submit-time validation should consume the same live resolveFieldRuleState result that drives the required star, not a snapshot taken at dialog mount.

Related (checked before filing — distinct issues)

Impact

Any "conditionally optional" field whose driving field has no defaultValue can never be left empty on a create form, even when the author's predicate says it may be. In the reporting app this pattern occurs 10+ times across objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpm:queue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions