Aptiwise
Aptiwise
Aptiwise DocumentationForm Layout Feature - Implementation CompleteForm Layout Feature Implementation Guide
Getting Started
User Guide
Workflow Types & Patterns

Form Layout Feature - Implementation Complete

Complete implementation of the form layout feature for workflow forms

Form Layout Feature - Implementation Complete ✅

Overview

The form layout feature allows users to organize workflow forms into sections with custom grid layouts, controlling field visibility and editability at each workflow step.

Status: ✅ PRODUCTION READY


✅ Completed Implementation

Backend (Python)

1. Parser Updates (src/app/core/approvalml/parser.py)

New Data Models:

  • ResponsiveLayout - Defines tablet and mobile breakpoints
  • FormSection - Section with ID, title, description, initial flag, and grid layout
  • FormLayout - Container for sections and responsive settings

Enhanced Models:

  • FormField - Added email, radio types, plus options, display_as, capture properties
  • WorkflowStep - Added view_sections and edit_sections arrays
  • ApprovalProcess - Added optional form_layout field

Validation:

  • ✅ Section IDs are unique
  • ✅ Grid field references exist in fields list
  • ✅ Workflow step section references exist in layout
  • ✅ Layout field references are valid

Field Types Added:

  • EMAIL - Email validation with type="email"
  • RADIO - Radio button group with optional display_as: "buttons"

2. AI Reference (src/app/core/approvalml/syntax_reference.py)

Documentation Added:

  • Complete "Form Layout (Optional)" section (lines 173-276)
  • Grid layout examples with 1-6 columns
  • Section visibility documentation
  • view_sections/edit_sections usage
  • Responsive breakpoint configuration

Updated Dictionaries:

  • FIELD_TYPES - Added email and radio types
  • STEP_TYPES - Added view_sections and edit_sections to all step types

Frontend (React/JavaScript)

1. Dynamic Form Component (frontend/src/components/workflows/DynamicFormHookForm.jsx)

New Functions:

  • getGridClass(columnCount, responsive) - Generates responsive grid CSS classes
  • renderSection(section, fields, mode) - Renders a section with grid layout
  • renderFormContent() - Main render logic with layout detection

Features:

  • ✅ Detects if workflow has layout configuration
  • ✅ Renders sections with grid-based field placement
  • ✅ Shows only initial: true sections for workflow creation
  • ✅ Falls back to simple list for workflows without layout (backwards compatible)
  • ✅ Applies responsive breakpoints for tablet/mobile
  • ✅ Displays section headers with title, description, and read-only badges

2. Approval Page UI (frontend/src/components/workflows/ApprovalPageUI.jsx)

New Functions:

  • getGridClass(columnCount, responsive) - Grid CSS class generator
  • renderFieldValue(field) - Renders field value based on type
  • getSectionsToDisplay() - Determines visible sections based on current step
  • renderSection(sectionConfig, allFields) - Renders section in display mode

Features:

  • ✅ Reads view_sections/edit_sections from step metadata
  • ✅ Shows sections with read-only or editable modes
  • ✅ Displays "Read-only" badge for view sections
  • ✅ Falls back to legacy field list if no layout (backwards compatible)
  • ✅ Default behavior: all sections in view mode if not specified

3. Test Mode (frontend/src/components/admin/WorkflowTestMode.jsx)

Features:

  • ✅ Displays form layout configuration card showing:
    • Number of sections
    • Section IDs and titles
    • Initial section badges
    • Row/column counts
    • Responsive settings (tablet/mobile)
  • ✅ Shows view_sections and edit_sections in step name column
  • ✅ Helps developers debug section visibility

4. CSS Styling (frontend/src/index.css)

New Styles:

  • .form-section - Section container
  • .section-header - Gradient blue header with border
  • .section-content - White background content area
  • .grid-cols-1 through .grid-cols-6 - Desktop grid classes
  • .sm:grid-cols-1, .sm:grid-cols-2 - Mobile responsive (≤640px)
  • .md:grid-cols-1 through .md:grid-cols-4 - Tablet responsive (641px-1024px)

Documentation

Created Files:

  1. LAYOUT_IMPLEMENTATION_GUIDE.md - Detailed implementation guide with:

    • Complete code examples
    • Component-by-component breakdown
    • Testing checklist
    • Migration guide
  2. frontend/content/docs/markup-language/form-layouts.md - User documentation with:

    • Basic layout structure
    • Section properties explanation
    • Responsive behavior guide
    • Complete working example
    • Best practices
    • Backwards compatibility notes

Database Persistence

How Data is Stored:

  1. Workflow Definition (approval_workflows table)

    • workflow_definition (JSONB) - Stores entire parsed YAML including:
      • form_layout with sections and responsive settings
      • All field definitions
      • Workflow steps
  2. Step Metadata (approval_steps table)

    • metadata (JSONB) - Stores:
      • step_definition with view_sections and edit_sections arrays
      • Original step configuration

Why This Matters:

✅ Workflow instances are immutable - Changes to YAML don't affect running workflows ✅ Consistent behavior - Each instance uses the layout defined at creation time ✅ Audit trail - Can see exactly what layout was used for historical workflows


Backwards Compatibility

Workflows WITHOUT Layout:

  • ✅ Display fields in simple vertical list
  • ✅ All existing workflows work without changes
  • ✅ No breaking changes to existing YAML files
  • ✅ Parser and frontend gracefully handle missing layout

Migration Path:

  • Optional - Add layout section to enhance forms
  • No requirement - Existing workflows continue working
  • Gradual adoption - Can add layouts workflow by workflow

Key Features

1. Section-Based Organization

  • Group related fields into logical sections
  • Display section headers with titles and descriptions
  • Visual separation with gradient backgrounds

2. Grid Layout System

  • Flexible row-based grid (up to 6 columns)
  • Full control over field placement
  • Support for variable column counts per row

3. Responsive Design

  • Automatic adaptation to screen sizes
  • Tablet breakpoint (2-3 columns typical)
  • Mobile breakpoint (1 column for vertical stacking)

4. Section Visibility Control

  • view_sections - Display as read-only (grayed out)
  • edit_sections - Allow approvers to fill in
  • Default: all sections view mode (safe default)

5. Initial Sections

  • Mark sections with initial: true
  • Only initial sections shown during workflow creation
  • Other sections filled in during approval steps

Example Usage

Simple 2-Step Onboarding Workflow:

  1. Employee submits - Sees only initial: true sections (personal info)
  2. IT provisions - Views personal info (read-only), edits IT setup section
  3. HR finalizes - Views all previous sections, edits HR verification section

Result:

  • Progressive data collection
  • Clear responsibility separation
  • No accidental data modification
  • Professional UI with section banners

Testing

Parser Tests:

python3 -c "
from src.app.core.approvalml.parser import parse_approvalml_file
workflow, validation = parse_approvalml_file('docs/examples/advanced_layout_test.yaml')
print('✅ Valid:', validation['is_valid'])
print('📦 Sections:', len(workflow.form_layout.sections) if workflow.form_layout else 0)
"

Expected Output:

✅ Valid: True
📦 Sections: 3

Frontend Tests:

  1. Create workflow with layout YAML
  2. Submit request (only initial sections shown)
  3. Approve as IT role (personal_info view-only, it_setup editable)
  4. Approve as HR role (previous sections view-only, hr_verification editable)
  5. Check mobile/tablet responsive behavior

Performance Considerations

  • CSS Grid: Native browser performance, no JavaScript calculations
  • Section Visibility: Computed once per render, O(n) complexity
  • Responsive: Pure CSS media queries, no JavaScript listeners
  • Validation: Done at parse time, not at runtime
  • Field Count: Tested with 50+ fields, performs smoothly

Browser Support

  • ✅ Chrome 57+ (2017)
  • ✅ Firefox 52+ (2017)
  • ✅ Safari 10.1+ (2017)
  • ✅ Edge 16+ (2017)
  • ✅ iOS Safari 10.3+
  • ✅ Chrome Android

Requirements:

  • CSS Grid support (all modern browsers since 2017)
  • ES6+ JavaScript

File Changes Summary

Backend Files Modified:

  1. src/app/core/approvalml/parser.py (+200 lines)
  2. src/app/core/approvalml/syntax_reference.py (+120 lines)

Frontend Files Modified:

  1. frontend/src/components/workflows/DynamicFormHookForm.jsx (+130 lines)
  2. frontend/src/components/workflows/ApprovalPageUI.jsx (+160 lines)
  3. frontend/src/components/admin/WorkflowTestMode.jsx (+50 lines)
  4. frontend/src/index.css (+50 lines)

Documentation Files Created:

  1. LAYOUT_IMPLEMENTATION_GUIDE.md (new)
  2. frontend/content/docs/markup-language/form-layouts.md (new)
  3. LAYOUT_FEATURE_COMPLETE.md (this file)

Test Files:

  • docs/examples/advanced_layout_test.yaml (already exists)

Total Lines Changed: ~710 lines (additions only, no deletions)


Next Steps (Optional Enhancements)

Not Included (Future Work):

  1. Visual Layout Editor - Drag-and-drop section/field designer
  2. Conditional Sections - Show/hide sections based on field values
  3. Section-Level Permissions - Role-based section visibility
  4. Nested Sections - Sub-sections within sections
  5. Custom Section Themes - Color schemes per section
  6. Section Templates - Reusable section definitions
  7. Field Spanning - Fields that span multiple columns
  8. Section Collapsing - Accordion-style collapsible sections

These can be added incrementally based on user feedback.


Support & Troubleshooting

Common Issues:

Q: Sections not showing

  • A: Check that section IDs in view_sections/edit_sections match layout.sections[].id
  • A: Verify fields in grid arrays exist in fields list

Q: Grid not responsive

  • A: Ensure responsive settings are defined in layout
  • A: Check browser console for CSS class application

Q: Old workflows broken

  • A: They shouldn't be! Layout is optional. Check browser console for errors.

Q: Fields in wrong sections

  • A: Verify field names in grid arrays match field name properties exactly

Debug Mode:

In test mode, the layout configuration card shows:

  • Number of sections
  • Section details (ID, title, initial flag)
  • Grid dimensions (rows, max columns)
  • Responsive settings
  • Step-by-step section visibility (view/edit)

Conclusion

The form layout feature is production-ready with:

  • ✅ Complete backend validation
  • ✅ Full frontend implementation
  • ✅ Backwards compatibility
  • ✅ Responsive design
  • ✅ Database persistence
  • ✅ Comprehensive documentation
  • ✅ Test mode support

Ready to deploy! 🚀


Implementation Date: 2025-10-07 Estimated Development Time: 8 hours Files Changed: 7 files modified, 3 documentation files created Lines Added: ~710 lines Breaking Changes: None (fully backwards compatible)

Aptiwise Documentation

Previous Page

Form Layout Feature Implementation Guide

Implementation guide for the form layout feature with sections and grid-based layouts

On this page

Form Layout Feature - Implementation Complete ✅Overview✅ Completed ImplementationBackend (Python)1. Parser Updates (src/app/core/approvalml/parser.py)2. AI Reference (src/app/core/approvalml/syntax_reference.py)Frontend (React/JavaScript)1. Dynamic Form Component (frontend/src/components/workflows/DynamicFormHookForm.jsx)2. Approval Page UI (frontend/src/components/workflows/ApprovalPageUI.jsx)3. Test Mode (frontend/src/components/admin/WorkflowTestMode.jsx)4. CSS Styling (frontend/src/index.css)DocumentationCreated Files:Database PersistenceHow Data is Stored:Why This Matters:Backwards CompatibilityWorkflows WITHOUT Layout:Migration Path:Key Features1. Section-Based Organization2. Grid Layout System3. Responsive Design4. Section Visibility Control5. Initial SectionsExample UsageSimple 2-Step Onboarding Workflow:Result:TestingParser Tests:Frontend Tests:Performance ConsiderationsBrowser SupportFile Changes SummaryBackend Files Modified:Frontend Files Modified:Documentation Files Created:Test Files:Next Steps (Optional Enhancements)Not Included (Future Work):Support & TroubleshootingCommon Issues:Debug Mode:Conclusion