Skip to content

Core: Trigger watchForError callbacks from setError#406

Merged
fernanDOTdo merged 1 commit into
mainfrom
fix-watch-for-error
Jun 24, 2026
Merged

Core: Trigger watchForError callbacks from setError#406
fernanDOTdo merged 1 commit into
mainfrom
fix-watch-for-error

Conversation

@fernanDOTdo

Copy link
Copy Markdown
Member

Design: Trigger watchForError callbacks from setError

Problem

ENGrid.watchForError() observes .en__errorList for added children, but ENGrid.setError() adds .en__field__error directly to a field wrapper. As a result, callbacks registered through watchForError do not run when setError displays a field-level error.

Goal

Make setError trigger all callbacks registered with watchForError, without breaking backward compatibility.

Constraints

  • Keep existing public signatures: setError(element, errorMessage) and watchForError(callback).
  • Preserve the deduplication behavior already in watchForError (callback key derived from callback.toString()).
  • The only current consumers are ENGrid.enableSubmit and iFrame.sendIframeHeight; both are idempotent.

Approach: Shared Callback Registry

Add a module-level Map<string, Function> to packages/scripts/src/engrid.ts. watchForError registers the callback in the map and also attaches the existing .en__errorList MutationObserver. setError iterates the map and invokes each registered callback after injecting the field-level error.

Changes

  • packages/scripts/src/engrid.ts
    • Add const errorCallbacks = new Map<string, Function>(); at module scope.
    • Refactor the callbackType derivation into a private helper so both watchForError and setError can use it.
    • In watchForError, register the callback in the map before attaching the observer.
    • In setError, after adding/updating .en__field__error, invoke every callback in the map.

Backward Compatibility

  • Signatures unchanged.
  • Callbacks now fire for field-level errors created by setError. This is the intended behavior change.
  • Existing deduplication keying is preserved.

@fernanDOTdo
fernanDOTdo merged commit 89af0d7 into main Jun 24, 2026
2 checks passed
@fernanDOTdo
fernanDOTdo deleted the fix-watch-for-error branch June 24, 2026 17:16
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