Fall back to first-error focus when the error summary isn't rendered - #3490
vivi-the-going-merry[bot] wants to merge 2 commits into
Conversation
js_validate's client-side validateFormSubmit() -> addAjaxFormErrors() never renders [data-frm-error-summary] - it only calls addFieldError() per field. checkForErrorsAndMaybeSetFocus() resolved focusErrorSummary true (the summary is "active" per filter, independent of js_validate) but focusFirstError false, so a failed submit on this path focused nothing at all - worse than the pre-#3408 behavior. Fall back to first-error-field focus when the summary was expected but isn't actually in the DOM, scoped to the submitting form's own container. Hand-patched js/formidable.min.js's matching function since SCRIPT_DEBUG is off in production/CI (same pattern PR#3408 used for this same file). Fixes Strategy11/formidable-pro#6763
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Repository: Strategy11/formidable-forms/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Resolves conflict in the hand-patched js/formidable.min.js: keeps master's querySelectorAll expansion (.frm_error, [data-frm-error]) and previousSibling null guard alongside this branch's focusErrorSummary fallback condition.
|
CI: all green except two pre-existing/unrelated failures, both confirmed rather than assumed:
Self-review (code-review/security-review/simplify) run against the diff. One code-review finding investigated and ruled out: whether the new Ready for review. |
What was broken
js_validate's client-side path (
validateFormSubmit()->addAjaxFormErrors(),js/formidable.js~2591) never renders the[data-frm-error-summary]markup - it only callsaddFieldError()per field.checkForErrorsAndMaybeSetFocus()still resolvedconfig.focusErrorSummarytrue (the summary is "active" per filter, independent of whetherjs_validateis enabled) whileconfig.focusFirstErrorwas forced false server-side (mutually exclusive with the summary, seeFrmAppHelper::resolve_error_focus_target()). Net effect: a failed submit on a form with "Validate Fields as User Completes Form" enabled focused nothing at all - worse than the pre-formidable-forms#3408behavior (first errored field).What changed
checkForErrorsAndMaybeSetFocus(): when the summary is expected (focusErrorSummarytrue) but isn't actually found in that error's own form container, fall through to the existing first-errored-field focus logic instead of returning early. No change when the summary is genuinely rendered (unaffected), and no change when an integration deliberately filters bothfrm_focus_first_errorandfrm_focus_error_summaryoff (still no auto-focus).js/formidable.min.js: hand-mirrored the same one-condition change into the matching minified function (js_suffix()serves this file wheneverSCRIPT_DEBUGis off) - not independently executed locally, verified by direct text diff against the source change plusnode --check.tests/cypress/e2e/Forms/fieldsInFormBuilder-validation.cy.js: added ahave.focusassertion to the existing "should validate forms with javascript setting" test, on the submit click where only the required Text field is invalid (email/phone already valid format there, avoiding native browser constraint-validation interference on the other submit click in the same test).How verified
Local: real Cypress run (
npx cypress run) against a localwp-envWordPress instance withjs_validateenabled via the form builder UI - confirmed red (assertion timeout) against unfixed code, green after the fix, and red again when the fix was temporarily reverted with the test kept. CI: see checks on this PR.Fixes Strategy11/formidable-pro#6763