Skip to content

x-currency-field: .value is stale during typing (reflects only on blur/change) #264

Description

@avanelsas

Follow-up to the x-select .value fix (#263). Surfaced by the same audit: which form controls' host .value reflects user interaction (what x-form's collect-values reads).

Problem

x-currency-field's value getter (define-value-prop!) reads the value attribute. The native input handler on-input-input keeps ElementInternals.setFormValue current and dispatches event-input, but does not write attr-value — only the change handler on-input-change (blur/Enter) does. So el.value is stale while the user is typing, reconciled only on blur/Enter.

Impact is narrower than x-select:

  • Native <form>/FormData submission is correct (setFormValue stays current on input).
  • x-form's collect-values reads el.value, so a submit triggered without a prior blur/change (e.g. Enter-to-submit while focused) or any .value read mid-edit gets the stale value. Clicking a submit button normally blurs first → change reconciles → fine.

Fix direction

Mirror the conforming pattern: make el.value reflect the current input. Either

  • write attr-value in on-input-input (as x-otp-input does on every keystroke — but careful not to reformat the focused/in-edit input), or
  • make the getter read the live inner <input>'s raw value (complicated here because the input shows a formatted display value, not the raw value).

Lower priority than #263x-currency-field isn't used in the demo, and normal click-submit reconciles via blur. Add a regression test asserting el.value after an input event.

Files: src/baredom/components/x_currency_field/x_currency_field.cljs (define-value-prop!, on-input-input, on-input-change).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions