Skip to content

Add Blueprint/formPrint compatibility to BootstrapRenderer - #111

Closed
f3l1x wants to merge 2 commits into
masterfrom
claude/implement-issue-63-tests-rYXMM
Closed

Add Blueprint/formPrint compatibility to BootstrapRenderer#111
f3l1x wants to merge 2 commits into
masterfrom
claude/implement-issue-63-tests-rYXMM

Conversation

@f3l1x

@f3l1x f3l1x commented Mar 29, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds compatibility with Nette's Blueprint::latte() functionality and the {formPrint} macro by making BootstrapRenderer work with regular Form instances, not just BootstrapForm.

Key Changes

  • Type flexibility: Changed attachForm() parameter type from BootstrapForm to Form to accept any form instance
  • String handling: Added support for string returns from getControl() and getLabel() methods, which Blueprint uses instead of Html objects
  • Validation safety: Introduced isShowValidation() helper method that safely checks if the form is a BootstrapForm before accessing validation properties, returning false for regular forms
  • Return type updates: Updated renderLabel() return type to Html|string to accommodate Blueprint's string-based rendering
  • Cloning support: Ensured the renderer can be cloned and attached to different form instances without errors

Implementation Details

  • The renderer now gracefully handles both Html objects and string returns from control methods
  • Validation styling is only applied when the form is actually a BootstrapForm instance, preventing errors when used with regular forms
  • All changes maintain backward compatibility with existing BootstrapForm usage
  • Added comprehensive test suite (BlueprintCompatibilityTest) covering various scenarios including different render modes, Bootstrap versions, and form types

Testing

Added 13 new tests verifying:

  • Blueprint Latte generation with BootstrapForm
  • Compatibility across all render modes (vertical, side-by-side, inline)
  • Bootstrap 5 support
  • Various input types and form groups
  • Renderer cloning and attachment to regular forms
  • Validation behavior with non-BootstrapForm instances

https://claude.ai/code/session_017S8dLXAbfF5iXKzYq8ADt2

This change enables the {formPrint} Latte macro to work with BootstrapForm.
Previously, using {formPrint} with BootstrapForm would fail because:

1. BootstrapRenderer::attachForm() only accepted BootstrapForm
2. The renderer directly accessed $this->form->showValidation which
   doesn't exist on regular Form objects
3. renderControl() and renderLabel() didn't handle string returns from
   getControl()/getLabel() which Blueprint's dummy controls return

Changes:
- Updated attachForm() to accept Form instead of BootstrapForm
- Added isShowValidation() helper method that safely checks the property
- Updated renderControl() to handle string returns for Blueprint compatibility
- Updated renderLabel() to handle string returns for Blueprint compatibility
- Added comprehensive test suite for Blueprint/formPrint functionality

Fixes: #63
dakorpar added a commit that referenced this pull request Aug 14, 2026
Direct coverage for what the {formPrint} fix added, which until now was
only exercised incidentally through one Blueprint case:

- BootstrapRow's lookupPath()/getLabel()/isRequired(), including that the
  path a fake control reports matches what a real sibling reports
- getOption() returning null for an unset key without raising a warning
- the renderer drawing a plain Nette\Forms\Form, directly and via a clone
- a Bootstrap 5 blueprint, asserting the v5 wrapper rather than v4's

The plain-form, cloned-renderer and Bootstrap 5 scenarios are adapted from
f3l1x's PR #111, which independently fixed the same Blueprint incompatibility.

Also call BootstrapForm::isShowValidation() rather than reaching for the
magic property, as #111 does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dakorpar

Copy link
Copy Markdown
Member

closed in favor of #132

@dakorpar dakorpar closed this Aug 14, 2026
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.

3 participants