Skip to content

Focus success message after AJAX submit - #3386

Open
vivi-the-going-merry[bot] wants to merge 2 commits into
masterfrom
fix/issue-6702-focus-message-after-submit
Open

vivi-the-going-merry[bot] wants to merge 2 commits into
masterfrom
fix/issue-6702-focus-message-after-submit

Conversation

@vivi-the-going-merry

Copy link
Copy Markdown
Contributor

What was broken

After a form is submitted via AJAX and the success message (.frm_message) replaces the form, focus stays wherever it was before the submit button was clicked. Screen reader users get no notification the message appeared.

Split from Strategy11/formidable-pro#6098. Prior art: #2677 (closed unmerged draft) — reused as a starting point, but its object.closest('.frm_forms')?.parentNode lookup was querying a subtree already detached from the document by replaceWith(), so the .focus() call was a silent no-op.

What changed

  • FrmFormsHelper::get_success_message() adds tabindex="-1" to the message div so it's programmatically focusable without joining the tab order.
  • js/formidable.js: after replaceContent.replaceWith(...), the newly inserted markup (not the parent container, and not the detached old subtree) is searched for .frm_message and focused via the existing focusInput() helper — the same helper the error-summary focus work already uses, so a message that appears mid slide-in animation is handled consistently.
  • New Cypress assertion in tests/cypress/e2e/admin.cy.js asserting the success message is focused after submit, alongside the existing content assertion.

How it was verified

No interactive browser-automation tool (playwright-cli) is available in this unattended session, so this wasn't driven live. Verification is the new Cypress assertion above plus CI — this is a fresh branch with no PR history to protect, so per this agent's own SOP the push-then-read-CI loop serves as the self-test here. Will confirm CI is green (run e2e tests label) before this is handed to review.

Closes Strategy11/formidable-pro#6702

Screen reader users get no notification when the success/error message
replaces the form after an AJAX submit, since focus stays wherever it
was before the submit button was clicked.

- tabindex="-1" on the message div (FrmFormsHelper::get_success_message)
  makes it programmatically focusable without adding it to the tab order.
- js/formidable.js focuses the message once it's live in the document.
  The old .frm_forms wrapper is already detached by the time the message
  needs to be looked up, so it's queried fresh from the still-attached
  parent captured before replaceWith() ran, not from the replaced-away
  subtree.

Closes Strategy11/formidable-pro#6702
- Reuse the existing focusInput() helper (already used by the error-summary
  a11y work) instead of a bare .focus() call, so a message that appears
  mid slide-in animation is handled the same way error focus already is.
- Scope the .frm_message lookup to the markup that was just inserted,
  not the form's whole parent container, so an unrelated element
  elsewhere on the page can never be focused instead.
- Tighten the Cypress assertion to check focus on the message element
  itself, and the PHP comment to not overclaim beyond the success case.
@vivi-the-going-merry vivi-the-going-merry Bot added the run e2e tests Run the Cypress end-to-end suite on this PR label Sep 18, 2026
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: Strategy11/formidable-forms/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 306fdf3c-54a6-4673-aae4-d132d5bbb975

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Sep 18, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in fc48e47...4281096 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Sep 18, 2026 8:56p.m. Review ↗
JavaScript Sep 18, 2026 8:56p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis run e2e tests Run the Cypress end-to-end suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants