Skip to content

Stop adding aria invalid directly to radio button and checkbox inputs#2507

Merged
Crabcyborg merged 4 commits into
masterfrom
stop_adding_aria_invalid_directly_to_radio_button_and_checkbox_inputs
Sep 25, 2025
Merged

Stop adding aria invalid directly to radio button and checkbox inputs#2507
Crabcyborg merged 4 commits into
masterfrom
stop_adding_aria_invalid_directly_to_radio_button_and_checkbox_inputs

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Sep 23, 2025

Related ticket https://secure.helpscout.net/conversation/3085736983/238704

This fixes issues caught by SiteImprove's Accessibility Checker.

Pre-release
formidable-6.24.2b.zip

What's changing
Radio buttons and checkboxes will no longer include aria-invalid. It isn't meant for these inputs. Instead, the role="radiogroup" or role="group" parents will use the aria-invalid attribute.

When testing
You can download the SiteImprove browser widget. It has links for various browsers here https://www.siteimprove.com/why-siteimprove/integrations/browser-extensions/

It's good to test this with an Accessibility tool like Voiceover. We want an invalid group to still appear as invalid to a screen reader. I tested this with Voiceover and it works.

This is the error that would previous show:
Screen Shot 2025-09-23 at 5 45 22 PM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 23, 2025

Walkthrough

Adds group-level aria-invalid on field container output when a field has validation errors and removes aria-invalid from individual checkbox/radio inputs by introducing new per-field methods and adjusting attribute assembly logic.

Changes

Cohort / File(s) Summary
Group-level aria-invalid injection
classes/models/FrmFieldFormHtml.php
Conditionally adds aria-invalid="true" to the input group container inside add_multiple_input_attributes when validation errors exist for the field.
Per-input aria-invalid suppression (checkbox/radio)
classes/models/fields/FrmFieldCheckbox.php, classes/models/fields/FrmFieldRadio.php
Adds set_aria_invalid_error( &$shortcode_atts, $args ) methods that unset aria-invalid from individual checkbox/radio input attributes so the group handles the error state.
Client-side error handling update
js/formidable.js
When adding/removing field errors, sets/clears aria-invalid on the group ancestor for checkboxes/radios and on the input for other field types (adjusts where ARIA invalid is applied/removed).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Renderer as Form Renderer
  participant FrmFieldFormHtml as FrmFieldFormHtml
  participant FieldCheckbox as FrmFieldCheckbox
  participant FieldRadio as FrmFieldRadio
  participant BrowserJS as formidable.js

  Note over User,Renderer: Render form or update validation state

  User->>Renderer: Request render / submit
  Renderer->>FrmFieldFormHtml: add_multiple_input_attributes(args)
  alt field has validation errors
    FrmFieldFormHtml->>FrmFieldFormHtml: Inject aria-invalid="true" on group container attributes
  else no errors
    FrmFieldFormHtml->>FrmFieldFormHtml: No aria-invalid on group
  end

  Note over Renderer,FieldCheckbox: Per-input attribute assembly
  Renderer->>FieldCheckbox: set_aria_invalid_error(&shortcode_atts, args)
  FieldCheckbox->>FieldCheckbox: Unset aria-invalid on individual checkbox inputs

  Renderer->>FieldRadio: set_aria_invalid_error(&shortcode_atts, args)
  FieldRadio->>FieldRadio: Unset aria-invalid on individual radio inputs

  Note over BrowserJS: Runtime updates after validation
  BrowserJS->>Renderer: add/remove field error
  alt field is radio/checkbox
    BrowserJS->>Renderer: set/clear aria-invalid on group ancestor
  else other field type
    BrowserJS->>Renderer: set/clear aria-invalid on input
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

action: needs qa, run analysis, run tests

Suggested reviewers

  • lauramekaj1
  • shervElmi

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change—stopping aria-invalid from being applied directly to radio and checkbox inputs—which matches the PHP and JS changes that move error indication to the group/container level.
Description Check ✅ Passed The PR description clearly explains the change (stop adding aria-invalid to radio and checkbox inputs and apply it to their group containers), links the related ticket, and provides testing guidance and a pre-release artifact, which matches the file summaries and PR objectives.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch stop_adding_aria_invalid_directly_to_radio_button_and_checkbox_inputs

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
classes/models/FrmFieldFormHtml.php (2)

534-537: Make attribute injection robust (replace role="group" or role="radiogroup")

Current replacement fails if the template uses role="radiogroup". Prefer a regex that matches either.

Apply this diff:

-		$this->html      = str_replace( ' role="group"', $html_attributes, $this->html );
+		$this->html      = preg_replace( '/\srole="(?:radio)?group"/', $html_attributes, $this->html, 1 );

529-533: Optional: append error id via aria-describedby on the group

Improves SR announcement without relying on per-input aria-invalid. Safe for both group and radiogroup.

Example (append if present, else set):

if ( ! empty( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
	$error_id = 'frm_error_' . $this->html_id;
	if ( ! empty( $attributes['aria-describedby'] ) ) {
		$attributes['aria-describedby'] .= ' ' . $error_id;
	} else {
		$attributes['aria-describedby'] = $error_id;
	}
}
classes/models/fields/FrmFieldRadio.php (1)

112-124: Silence unused $args and replace placeholder @SInCE

Avoid PHPMD UnusedFormalParameter and fill in the real version before merge.

Apply this diff to silence PHPMD:

 public function set_aria_invalid_error( &$shortcode_atts, $args ) {
+		// Silence unused parameter from parent signature.
+		(void) $args;
 		unset( $shortcode_atts['aria-invalid'] );
 }

And update @since x.x to the release version for this change.

classes/models/fields/FrmFieldCheckbox.php (1)

112-123: Silence unused $args and replace placeholder @SInCE

Mirror the radio fix to keep static analysis clean and docs accurate.

Apply this diff:

 public function set_aria_invalid_error( &$shortcode_atts, $args ) {
+		// Silence unused parameter from parent signature.
+		(void) $args;
 		unset( $shortcode_atts['aria-invalid'] );
 }

And update @since x.x to the actual release version.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8268919 and fe9955b.

📒 Files selected for processing (3)
  • classes/models/FrmFieldFormHtml.php (1 hunks)
  • classes/models/fields/FrmFieldCheckbox.php (1 hunks)
  • classes/models/fields/FrmFieldRadio.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
classes/models/fields/FrmFieldRadio.php (2)
classes/models/fields/FrmFieldCheckbox.php (1)
  • set_aria_invalid_error (121-123)
classes/models/fields/FrmFieldType.php (1)
  • set_aria_invalid_error (1046-1048)
classes/models/fields/FrmFieldCheckbox.php (2)
classes/models/fields/FrmFieldRadio.php (1)
  • set_aria_invalid_error (122-124)
classes/models/fields/FrmFieldType.php (1)
  • set_aria_invalid_error (1046-1048)
🪛 PHPMD (2.15.0)
classes/models/fields/FrmFieldRadio.php

122-122: Avoid unused parameters such as '$args'. (undefined)

(UnusedFormalParameter)

classes/models/fields/FrmFieldCheckbox.php

121-121: Avoid unused parameters such as '$args'. (undefined)

(UnusedFormalParameter)

🔇 Additional comments (2)
classes/models/fields/FrmFieldRadio.php (1)

112-124: Good: per-input aria-invalid removed for radios; handled at radiogroup

This aligns with ARIA and the new group-level handling.

classes/models/fields/FrmFieldCheckbox.php (1)

112-123: Good: per-input aria-invalid removed for checkboxes; group-level flow supported

Matches the radiogroup approach and the form HTML changes.

Comment thread classes/models/FrmFieldFormHtml.php
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe9955b and 1603355.

📒 Files selected for processing (1)
  • js/formidable.js (2 hunks)

Comment thread js/formidable.js
Comment thread js/formidable.js
@Crabcyborg Crabcyborg added this to the 6.25 milestone Sep 23, 2025
@Crabcyborg Crabcyborg removed the request for review from lauramekaj1 September 25, 2025 12:27
@Crabcyborg Crabcyborg merged commit ac3d591 into master Sep 25, 2025
36 checks passed
@Crabcyborg Crabcyborg deleted the stop_adding_aria_invalid_directly_to_radio_button_and_checkbox_inputs branch September 25, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant