Skip to content

fix(flow): enforce native form validation and leave script validation to the GUI - #1371

Merged
abrichr merged 3 commits into
mainfrom
fix/api-step-native-validation
Oct 20, 2026
Merged

abrichr merged 3 commits into
mainfrom
fix/api-step-native-validation

Conversation

@abrichr

@abrichr abrichr commented Oct 19, 2026

Copy link
Copy Markdown
Member

Fifth of six fixes from an external review of #1269. Stacked on #1370 (then #1369, #1368).

Bug

Only validate.js presence rules were enforced. A browser also checks native HTML constraints before it submits, and a form's own script can validate or rewrite values. The API step skipped both.

Fix

Evaluated by the API step (build_body, on what it sends):

  • native constraints: required, minlength, maxlength, pattern, min, max, and the email, url, number/range and date input types;
  • validate.js rules: presence, length, format, numericality, email.

Left to the GUI (refused at proposal; at run time the step is unavailable when the live form has it):

  • an on* handler on the form (onsubmit) or on a field the save sends (onchange, oninput, onblur);
  • a page script listening for submit;
  • a validate.js rule of any other kind.

On the real OpenEMR recording this finds three things:

  • onsubmit='return submitme(1,event,"DEM",constraints)';
  • onchange='checkSkipConditions();capitalizeMe(this);' on each name field. capitalizeMe rewrites the typed value, so the API step would have saved a different name than the GUI;
  • a custom pastDate rule on the date of birth, which the API step never enforced.

So the referral save stays on the GUI. The reviewer's escape hatch, letting qualification show that the server enforces a script-only rule, is documented as not built. Python's re approximates the browser's pattern; a pattern that doesn't compile keeps the save on the GUI.

Tests

tests/test_api_step_native_validation.py (new):

  • each native constraint refuses what the browser would and accepts valid values;
  • validate.js length, format and numericality are enforced;
  • the actuator refuses an invalid value before sending;
  • four script cases are refused at proposal and unavailable at run time: onsubmit, onchange, a submit listener, and a pastDate rule.

80 pass with the API-tier, approval, provenance, URL and other-writes tests. API_TIER.md is updated.

Synthetic values only.

🤖 Generated with Claude Code

… to the GUI

Review of #1269: only validate.js presence rules were enforced. A browser
also checks native HTML constraints, and a form's own script can validate
or rewrite values before it submits.

- build_body checks required, minlength, maxlength, pattern, min, max and
  the email, url, number and date input types on what it sends, and the
  validate.js presence, length, format, numericality and email rules.
- A form whose script the API step can't run stays on the GUI: an on*
  handler on the form or on a sent field (OpenEMR's capitalizeMe rewrites
  the typed name), a page script listening for submit, or a validate.js rule
  of another kind (OpenEMR's pastDate). Refused at proposal; unavailable at
  run time when the live form has it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@abrichr

abrichr commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

Included in batch #1383, which runs CI once for several reviewed PRs. This PR is marked merged when #1383 merges. Please don't push here unless asked; a new commit leaves it out of the batch.

abrichr added a commit that referenced this pull request Oct 20, 2026
batch: API-step fixes, compatibility matrix and local-edit classification (#1370 #1371 #1372 #1364 #1374 #1366)
Base automatically changed from fix/api-proposal-refuse-other-writes to main October 20, 2026 00:24
@abrichr
abrichr merged commit a453741 into main Oct 20, 2026
29 of 35 checks passed
@abrichr
abrichr deleted the fix/api-step-native-validation branch October 20, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant