Skip to content

fix(templates): improve standalone kit templates for modal and textarea support#45

Merged
adnaan merged 2 commits intomainfrom
fix/ui-polish-standalone-templates
Jan 18, 2026
Merged

fix(templates): improve standalone kit templates for modal and textarea support#45
adnaan merged 2 commits intomainfrom
fix/ui-polish-standalone-templates

Conversation

@adnaan
Copy link
Copy Markdown
Contributor

@adnaan adnaan commented Jan 18, 2026

Summary

  • Add IsTextarea check to render text type fields as <textarea> instead of <input type="text">
  • Convert server-state modals ({{if .IsAdding}}) to client-side modals using lvt-modal-open/lvt-modal-close attributes
  • Add close button (X) to both add and edit modal headers for consistency with component-based templates

Background

The standalone templates (template.tmpl.tmpl) are used when generating resources in single kit mode. Previously they had several issues:

  1. Textarea bug: Text fields (e.g., content:text) were rendered as <input type="text"> instead of <textarea>
  2. Broken modals: Add modal used non-existent server state (IsAdding) causing the modal to never open when clicking the "Add" button
  3. Missing close buttons: Modal headers lacked close buttons (X) unlike the component-based templates

Test plan

  • Generated test apps with multi, single, and simple kits
  • Captured screenshots of all UI states (add modal, edit modal, forms, list views)
  • Verified textarea fields render correctly for text type
  • Verified modals open/close properly with client-side modal system
  • Ran app creation tests (4/4 passed)
  • Ran resource generation tests (13/13 passed, including TestResourceGen_TextareaFields)

🤖 Generated with Claude Code

…ea support

- Add IsTextarea check to render text fields as <textarea> instead of <input>
- Convert server-state modals ({{if .IsAdding}}) to client-side modals
  using lvt-modal-open/close attributes for proper modal functionality
- Add close button (X) to both add and edit modal headers
- Fix edit form field accessor to use camelCase instead of title

The standalone templates (template.tmpl.tmpl) are used when generating
resources in single kit mode. Previously they had several issues:
1. Text fields were rendered as <input type="text"> instead of <textarea>
2. Add modal used non-existent server state (IsAdding) causing modal to
   never open
3. Modal headers lacked close buttons unlike the component-based templates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 18, 2026 13:12
@claude
Copy link
Copy Markdown

claude bot commented Jan 18, 2026

PR Review: Fix standalone kit templates for modal and textarea support

Summary

This PR fixes critical bugs in the standalone kit templates (template.tmpl.tmpl) used in single kit mode. The changes align the standalone templates with the component-based templates and add proper textarea support.

Code Quality ✅

Strengths:

  • Clean, focused changes that address specific issues
  • Consistent implementation across both multi and single kit templates
  • Follows existing template patterns and conventions
  • Proper use of template delimiters and Go template syntax

Observations:

  • The changes correctly mirror the component-based templates (form.tmpl), ensuring consistency
  • Template syntax is properly formatted with correct spacing and attribute handling

Bug Fixes ✅

1. Textarea Support

  • Issue: Text fields (e.g., content:text) rendered as <input type="text"> instead of <textarea>
  • Fix: Added IsTextarea check as first condition in field rendering logic
  • Validation: Verified in internal/parser/fields.go:109-110 that text, textarea, and longtext types correctly set IsTextarea: true

2. Modal Functionality

  • Issue: Add modal used server-state check {{if .IsAdding}} which doesn't exist in standalone mode, preventing modals from opening
  • Fix: Converted to client-side modal system using lvt-modal-open/lvt-modal-close attributes
  • Validation: Checked livetemplate-client.browser.js - modal delegation is properly implemented and tested in e2e/modal_test.go

3. Close Button Consistency

  • Issue: Modal headers lacked close buttons (X) unlike component-based templates
  • Fix: Added close button to both add and edit modal headers
  • Validation: Matches component template structure from internal/kits/system/multi/components/form.tmpl:14

Potential Issues ⚠️

Minor: Field Accessor Inconsistency (Already Fixed)

The edit form now uses .[[.Name | camelCase]] for field access, which is correct. Previous code used .[[.Name | title]] which would have been incorrect for fields like user_name (would look for .UserName instead of .userName). This is properly fixed in lines 143, 145, 148, 151, 154.

Observation: Edit Modal Close Button

In the edit modal (line 126), the close button uses lvt-click="cancel_edit" instead of lvt-modal-close="edit-modal". This is acceptable if there's server-side cleanup needed, but worth noting for consistency:

  • Add modal cancel: lvt-modal-close="add-modal" (client-side only)
  • Edit modal close: lvt-click="cancel_edit" (may involve server-side state cleanup)

This is likely intentional to preserve the existing edit cancellation behavior.

Performance ✅

No performance concerns:

  • Client-side modals are more performant than server-side state management
  • Textarea rendering has no performance impact
  • Template changes are compile-time, no runtime overhead

Security ✅

No security issues identified:

  • Proper HTML escaping maintained via Go templates
  • No XSS vulnerabilities introduced
  • Modal attributes follow secure patterns (ARIA attributes, proper role declarations)

Test Coverage ✅

Excellent test coverage:

  • TestResourceGen_TextareaFields specifically validates textarea rendering (lines 353-382 in e2e/resource_generation_test.go)
  • TestResourceGen_EditModeModal validates modal functionality (lines 281-312)
  • Modal tests exist in e2e/modal_test.go with comprehensive browser-based testing
  • PR description mentions all tests passing (4/4 app creation, 13/13 resource generation)

Recommendations

1. Consider Edit Modal Close Button Consistency (Low Priority)

If the edit modal doesn't require server-side cleanup on close, consider using lvt-modal-close="edit-modal" instead of lvt-click="cancel_edit" for consistency with the add modal. However, if server-side cleanup is needed, the current implementation is correct.

2. Documentation (Optional)

Consider adding a comment in the template explaining the difference between IsTextarea and regular string fields for future maintainers:

{{/* Use textarea for text/longtext types, input for regular strings */}}
[[- if .IsTextarea]]

Final Assessment

Approve ✅

This is a well-implemented bug fix that:

  • Solves real user-facing issues (broken modals, incorrect field rendering)
  • Maintains consistency with component-based templates
  • Includes comprehensive test coverage
  • Follows existing code patterns and conventions
  • Has no security, performance, or quality concerns

The changes are minimal, focused, and correct. Great work on the test coverage and detailed PR description!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes several template issues in the standalone kit templates (multi and single) to improve modal functionality and textarea field rendering.

Changes:

  • Add textarea support by checking IsTextarea before rendering string fields
  • Convert add modal from broken server-state ({{if .IsAdding}}) to working client-side modal system
  • Add close buttons (X) to modal headers for better UX consistency
  • Fix field access in edit modal from title filter to camelCase filter

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/kits/system/single/templates/resource/template.tmpl.tmpl Updated standalone template for single kit with textarea support, client-side add modal, close buttons, and corrected field access
internal/kits/system/multi/templates/resource/template.tmpl.tmpl Updated standalone template for multi kit with identical changes to maintain consistency

Address Claude bot review suggestion to document the IsTextarea check
for future maintainers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Jan 18, 2026

Additional Review Notes

I've reviewed PR #45 and want to highlight a few additional observations beyond the existing review:

Code Quality & Best Practices ✅

Excellent consistency: The changes are identically applied to both multi and single kit templates, which is critical for maintainability. This parallel structure ensures that users get the same experience regardless of which kit they choose.

Template comment added: The second commit addresses documentation by adding the helpful comment [[/* Use textarea for text/longtext types, input for regular strings */]] at template.tmpl.tmpl:86. This is exactly the kind of inline documentation that helps future maintainers understand the logic.

Architecture Observations

Modal System Migration: The conversion from server-side state ({{if .IsAdding}}) to client-side modals (lvt-modal-open/lvt-modal-close) is architecturally sound. This:

  • Reduces server round-trips
  • Improves responsiveness
  • Aligns standalone templates with component-based templates
  • Follows the established pattern already working in component templates

Asymmetric Close Behavior (Intentional): There's an intentional difference worth noting:

  • Add modal cancel button: Uses lvt-modal-close="add-modal" (client-side only)
  • Edit modal close button: Uses lvt-click="cancel_edit" (server-side handler)

This asymmetry makes sense because:

  1. Adding: No server state to clean up, pure client-side interaction
  2. Editing: Needs to clear EditingID server-side state (see {{if ne .EditingID 0}} at line 117)

Bug Fix Validation ✅

Textarea Support: Verified that internal/parser/fields.go correctly identifies text, textarea, and longtext types and sets IsTextarea: true. The template logic correctly checks IsTextarea before eq .GoType "string" to ensure proper precedence.

Field Accessor Fix: The change from .[[.Name | title]] to .[[.Name | camelCase]] in edit forms (lines 145, 147, 150, 153, 156) fixes a critical bug where fields like user_name would incorrectly look for .UserName instead of .userName.

Test Coverage ✅

Comprehensive testing mentioned in PR description:

  • 4/4 app creation tests passed
  • 13/13 resource generation tests passed
  • Specific TestResourceGen_TextareaFields test validates the textarea functionality

Minor Suggestions

  1. Modal ID Consistency: The add modal uses id="add-modal" and data-modal-id="add-modal". Consider whether data-modal-id is redundant with id, though this may be required by the modal system implementation.

  2. ARIA Attributes: The add modal properly includes hidden, aria-hidden="true", and role="dialog". Verify that the modal JS toggles aria-hidden when opening/closing for screen reader accessibility.

Final Verdict: LGTM

This is a high-quality bug fix that:

  • Solves real user-facing issues with clear before/after behavior
  • Maintains architectural consistency
  • Includes proper test coverage
  • Contains helpful inline documentation
  • Follows conventional commit format

No blocking issues identified. Ready to merge.

@adnaan adnaan merged commit 84132a2 into main Jan 18, 2026
2 checks passed
@adnaan adnaan deleted the fix/ui-polish-standalone-templates branch January 18, 2026 19:02
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.

2 participants