Skip to content

fix(InputGroup): only set tag ID when input has none#39

Merged
Vitexus merged 1 commit into
mainfrom
fix/formgroup-bootstrap5
Jun 13, 2026
Merged

fix(InputGroup): only set tag ID when input has none#39
Vitexus merged 1 commit into
mainfrom
fix/formgroup-bootstrap5

Conversation

@Vitexus

@Vitexus Vitexus commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

  • InputGroup::__construct was calling $input->setTagID() unconditionally, overwriting any ID the input already had
  • This broke widgets like selectize that capture the element ID at construction time (the JS $('#id').selectize({...}) binding targeted the old ID, but the rendered HTML had the new one)
  • Fix: only call setTagID() when the input does not already have an ID

Test plan

  • Verify selectize-enhanced selects (e.g. executor chooser on schedule.php) render icons correctly after the fix
  • Verify label for= attribute still correctly references the input ID
  • Verify plain inputs without a pre-set ID still get an ID assigned

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed input group behavior where custom element identifiers were being unconditionally overwritten. The component now intelligently preserves pre-existing IDs while maintaining full accessibility support for form labels, ARIA attributes, and assistive technology like screen readers.

Unconditionally calling setTagID() overwrites any ID the input already
has (e.g. set by selectize() for its JS binding), breaking widgets like
selectize that capture the element ID at construction time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The InputGroup constructor now conditionally assigns a tag ID to its input element. Instead of unconditionally overwriting the tag ID via setTagID(), it first checks whether the input already has one using getTagID(), and only assigns a new tag ID when needed. This preserves any pre-existing IDs while ensuring the input has a tag ID for label and ARIA wiring.

Changes

InputGroup tag ID preservation

Layer / File(s) Summary
Preserve existing input tag IDs during InputGroup initialization
src/Ease/TWB5/InputGroup.php
The constructor guards setTagID() behind a check for existing tag IDs via getTagID(). Only when the input lacks a tag ID does setTagID() execute, allowing user-provided or pre-existing IDs to persist while ensuring label/ARIA wiring can reference a tag ID.

Poem

🐰 A tag ID passed with care,
Now survives the constructor's snare,
If it exists, we leave it be,
Only empty tags get one from thee!
Preserve the preset, guard the way,
Let existing identities stay! 🏷️

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(InputGroup): only set tag ID when input has none' directly and clearly summarizes the main change: conditional tag ID assignment based on whether an input already has an ID.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/formgroup-bootstrap5

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/Ease/TWB5/InputGroup.php (2)

34-36: 🏗️ Heavy lift

Add test coverage for the conditional ID assignment.

The fix preserves pre-existing input IDs, which is critical for JavaScript widgets like selectize. Consider adding unit tests to verify:

  1. Inputs with pre-existing IDs are not overwritten
  2. Inputs without IDs receive auto-generated IDs
  3. Label for= attribute correctly references the input ID in both cases

This would prevent regression and document the intended behavior.

Would you like me to help draft test cases for this fix?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Ease/TWB5/InputGroup.php` around lines 34 - 36, Add unit tests covering
the conditional ID assignment in InputGroup: create three tests that (1)
construct or mock an input with a pre-set ID and assert that after InputGroup
rendering the input ID remains unchanged (use the input object's
getTagID/setTagID methods to locate behavior), (2) construct an input without an
ID and assert that after rendering an auto-generated ID is assigned (getTagID
returns a non-empty, unique value), and (3) for both cases assert that the
generated label's for attribute matches the input's getTagID value (exercise the
InputGroup rendering/path that emits the <label for="..."> output). Ensure tests
target the InputGroup code path that calls $input->getTagID() and
$input->setTagID() so pre-existing IDs are preserved and missing IDs are
generated, and add assertions to prevent regressions.

34-36: 💤 Low value

Consider a more explicit ID check to handle edge cases.

Using empty() will return true for an ID of "0" (a valid but unusual HTML id), which would cause the guard to incorrectly call setTagID() and overwrite it. While this edge case is unlikely in practice, a more defensive check would be:

if (!$input->getTagID()) {
    $input->setTagID();
}

or explicitly:

if ($input->getTagID() === null || $input->getTagID() === '') {
    $input->setTagID();
}

Note: FormGroup.php uses the same empty() pattern (see context snippet), so the current code is consistent with the existing codebase convention.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Ease/TWB5/InputGroup.php` around lines 34 - 36, The guard uses
empty($input->getTagID()) which treats the string "0" as missing and can
overwrite a valid id; replace that check in InputGroup.php with a stricter test
such as if ($input->getTagID() === null || $input->getTagID() === '') {
$input->setTagID(); } (or alternatively if (!$input->getTagID()) if you prefer
the slightly different semantics), keeping references to the input->getTagID() /
input->setTagID() calls so the ID is only generated when truly absent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/Ease/TWB5/InputGroup.php`:
- Around line 34-36: Add unit tests covering the conditional ID assignment in
InputGroup: create three tests that (1) construct or mock an input with a
pre-set ID and assert that after InputGroup rendering the input ID remains
unchanged (use the input object's getTagID/setTagID methods to locate behavior),
(2) construct an input without an ID and assert that after rendering an
auto-generated ID is assigned (getTagID returns a non-empty, unique value), and
(3) for both cases assert that the generated label's for attribute matches the
input's getTagID value (exercise the InputGroup rendering/path that emits the
<label for="..."> output). Ensure tests target the InputGroup code path that
calls $input->getTagID() and $input->setTagID() so pre-existing IDs are
preserved and missing IDs are generated, and add assertions to prevent
regressions.
- Around line 34-36: The guard uses empty($input->getTagID()) which treats the
string "0" as missing and can overwrite a valid id; replace that check in
InputGroup.php with a stricter test such as if ($input->getTagID() === null ||
$input->getTagID() === '') { $input->setTagID(); } (or alternatively if
(!$input->getTagID()) if you prefer the slightly different semantics), keeping
references to the input->getTagID() / input->setTagID() calls so the ID is only
generated when truly absent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4fda122b-34c5-483e-8f66-4f3c901e3723

📥 Commits

Reviewing files that changed from the base of the PR and between 7e00ec8 and 93568d2.

📒 Files selected for processing (1)
  • src/Ease/TWB5/InputGroup.php

@Vitexus Vitexus merged commit e312448 into main Jun 13, 2026
1 of 2 checks passed
@Vitexus Vitexus deleted the fix/formgroup-bootstrap5 branch June 13, 2026 21:43
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