Skip to content

Added : Per-option HTML attributes for and multi-option inputs. #72

Merged
harikt merged 2 commits into
auraphp:6.xfrom
harikt:attributes
May 23, 2026
Merged

Added : Per-option HTML attributes for and multi-option inputs. #72
harikt merged 2 commits into
auraphp:6.xfrom
harikt:attributes

Conversation

@harikt
Copy link
Copy Markdown
Member

@harikt harikt commented May 23, 2026

Fixes #48 .

Summary by CodeRabbit

  • New Features

    • Per-option HTML attributes for checkbox and radio inputs, merged over shared attributes; input helpers validate option attribute formats and error on invalid usage.
  • Documentation

    • Expanded form helper docs with examples for grouped options, automatic name suffixing, and per-option {label, attribs} usage.
  • Tests

    • Added tests covering per-option attribute rendering, overrides, reset behavior, and invalid-attribute errors.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Walkthrough

Adds per-option HTML attribute support to multi-option checkbox and radio helpers. AbstractChecked::prep() normalizes { label, attribs } option specs and stores per-value attribs; Checkbox::multiple() and Radio::multiple() merge those per-option attribs with shared attributes when rendering. Docs, changelog, tests, and an InvalidArgument exception were added.

Changes

Per-option attributes for checkbox and radio helpers

Layer / File(s) Summary
Per-option attribute foundation
src/Exception/InvalidArgument.php, src/Helper/Input/AbstractChecked.php
Adds Aura\Html\Exception\InvalidArgument. AbstractChecked introduces options_attribs and overrides prep(array $spec) to extract per-option attribs and normalize options[$value] to a label. Invalid non-array attribs throw InvalidArgument.
Checkbox per-option attributes
src/Helper/Input/Checkbox.php, tests/Helper/Input/CheckboxTest.php
Checkbox::multiple() looks up per-option attribs and renders each checkbox with array_merge($this->attribs, $option_attribs). Tests cover inline attrib emission, global override, reset between calls, and invalid-attribs error.
Radio per-option attributes
src/Helper/Input/Radio.php, tests/Helper/Input/RadioTest.php
Radio::multiple() fetches per-option attribs and merges them with base attributes for each radio input. Tests verify inline attribs render and override global attributes where provided.
Documentation and changelog
README-FORMS.md, CHANGELOG.md
README adds examples for checkbox and radio showing per-option { label, attribs } syntax and merge behavior; CHANGELOG records the feature and moves related Title/HelperLocator notes into the 6.0.0 section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jakejohns
  • koriym
  • pmjones

Poem

🐰 Hopping through options, small and neat,
Each checkbox and radio finds its seat,
With attribs that merge and labels that sing,
Forms wear new ribbons — what joy they bring! 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and incomplete—it uses placeholder symbols instead of actual HTML tag names (checkbox and radio), making it unclear what the change entails. Replace placeholder symbols with actual tag/helper names: 'Added: Per-option HTML attributes for checkbox and radio multi-option inputs.'
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request fully implements the coding requirements from issue #48: adds per-option HTML attribute support for multi-checkbox (and multi-radio) inputs with proper validation and merging logic.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing per-option attributes for checkbox and radio helpers, including tests and documentation—no unrelated modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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 (1)
README-FORMS.md (1)

132-132: ⚡ Quick win

Use array format for consistency with multiple checkbox examples.

The earlier "Multiple checkboxes" example (line 110) uses an array for value even with multiple selections: 'value' => array('yes', 'maybe'). For consistency, this per-option attributes example should also use array format, e.g., 'value' => array('yes'), to reinforce that multiple checkbox inputs expect an array of checked values.

📝 Suggested consistency improvement
     'type'    => 'checkbox',
     'name'    => 'foo',
-    'value'   => 'yes',
+    'value'   => array('yes'),
     'options' => array(
🤖 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 `@README-FORMS.md` at line 132, The per-option attributes example uses a scalar
'value' => 'yes' but should follow the multiple-checkboxes convention and use an
array; update the example where the option attributes are defined (the 'value'
key in that per-option attributes block) to use an array form (e.g.,
array('yes')) so it matches the "Multiple checkboxes" example and clarifies that
checked values are arrays.
🤖 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.

Inline comments:
In `@src/Helper/Input/AbstractChecked.php`:
- Around line 85-88: AbstractChecked::prep() currently assigns
$option['attribs'] directly into $this->options_attribs which can be non-array
and cause TypeError in Checkbox/Radio where array_merge($this->attribs,
$option_attribs) is used; update the loop in AbstractChecked::prep() to validate
that $option['attribs'] is an array and if not, coerce or replace it with an
empty array (e.g. use is_array check or cast) before storing into
$this->options_attribs and ensure $this->options still gets the label
fallback—this fixes downstream array_merge in Checkbox.php and Radio.php.

---

Nitpick comments:
In `@README-FORMS.md`:
- Line 132: The per-option attributes example uses a scalar 'value' => 'yes' but
should follow the multiple-checkboxes convention and use an array; update the
example where the option attributes are defined (the 'value' key in that
per-option attributes block) to use an array form (e.g., array('yes')) so it
matches the "Multiple checkboxes" example and clarifies that checked values are
arrays.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19c87286-04f5-4c99-85dc-ecac39949dab

📥 Commits

Reviewing files that changed from the base of the PR and between 1a78d54 and f47b476.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • README-FORMS.md
  • src/Helper/Input/AbstractChecked.php
  • src/Helper/Input/Checkbox.php
  • src/Helper/Input/Radio.php
  • tests/Helper/Input/CheckboxTest.php
  • tests/Helper/Input/RadioTest.php

Comment thread src/Helper/Input/AbstractChecked.php
@harikt
Copy link
Copy Markdown
Member Author

harikt commented May 23, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

✅ Actions performed

Full review triggered.

@harikt harikt merged commit 5499acb into auraphp:6.x May 23, 2026
7 checks passed
@harikt harikt deleted the attributes branch May 23, 2026 06:17
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