mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-22 04:21:32 +02:00
| .. | ||
| app.js | ||
| data.js | ||
| form-trigger.handlebars | ||
| index.html | ||
| package.json | ||
| README.md | ||
Handlebars Client-Side Renderer
A simple JavaScript project that renders HTML pages using Handlebars templates with hot reload functionality. This project specifically renders the form-trigger.handlebars template with customizable form data.
Features
- 🔄 Hot Reload: Automatically reloads when template files change
- 🎨 Live Editing: Edit form data in JSON format and see changes instantly
- 🎯 Element Highlighting: Focus and highlight specific form elements by ID
- 📱 Responsive: Works on desktop and mobile devices
- 🚀 Client-Side Only: No server-side processing required
- 💾 Auto-Save: Form data is automatically saved to localStorage
- 🖼️ Iframe Rendering: Form renders in isolated iframe for better testing
Getting Started
Prerequisites
- Node.js (for the development server)
- A modern web browser
Installation
-
Install dependencies:
npm install -
Start the development server:
npm run dev -
Open your browser to
http://localhost:3000
Alternative Start Method
If you just want to start the server without auto-opening:
npm start
Usage
- Edit Form Data: Modify the JSON data in the textarea to customize the form
- Render Template: Click "Render Template" or press
Ctrl+Enterto update the rendered form - Highlight Elements: Use the "Highlight Field" section to focus specific form elements by ID
- Hot Reload: The template will automatically reload when you modify
form-trigger.handlebars
Using the Highlight Field Feature
- Enter a form field ID in the "Highlight Field" input (e.g.,
fullName,email,message) - Click "Send" or press
Enterto focus that element in the iframe - The element will be highlighted with a yellow glow and scrolled into view
- Status messages will confirm if the element was found or not
Sample Form Data Structure
The form data includes:
- Basic Info:
formTitle,formDescription,buttonLabel - Form Fields: Array of field objects with different types:
- Text inputs
- Email inputs
- Textareas
- Select dropdowns
- Multi-select checkboxes/radio buttons
- File uploads
- HTML content blocks
- Hidden fields
Form Field Types
Each field in the formFields array can have these properties:
{
id: "fieldId",
label: "Field Label",
type: "text|email|tel|number|date",
placeholder: "Placeholder text",
defaultValue: "Default value",
inputRequired: "form-required", // or ""
errorId: "error-fieldId",
// For different field types:
isInput: true, // Regular input fields
isTextarea: true, // Textarea fields
isSelect: true, // Dropdown select
isMultiSelect: true, // Checkbox/radio groups
isFileInput: true, // File upload
isHtml: true, // HTML content
isHidden: true // Hidden fields
}
File Structure
handlebars-project/
├── index.html # Main HTML file
├── app.js # Application logic
├── data.js # Sample form data
├── form-trigger.handlebars # Handlebars template
├── package.json # Project configuration
└── README.md # This file
Development
Hot Reload
The project includes two types of hot reload:
- Live Server: Reloads the entire page when any file changes
- Template Hot Reload: Automatically reloads just the Handlebars template when it changes
Debugging
Open browser developer tools to see console logs. The app exposes these global functions for debugging:
renderTemplate(): Re-render the current templateresetData(): Reset form data to defaultswindow.app: Access the main application instance
Customization
- Styling: Modify the CSS in
index.htmlor add custom CSS in the form data - Template: Edit
form-trigger.handlebarsto change the form structure - Data: Modify
data.jsto change default form configuration
Browser Compatibility
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
Troubleshooting
Template Not Loading
- Ensure
form-trigger.handlebarsexists in the project directory - Check browser console for fetch errors
- Verify the development server is running
JSON Parse Errors
- Validate your JSON syntax in the textarea
- Use online JSON validators if needed
- Check browser console for specific error messages
Hot Reload Not Working
- Ensure live-server is installed:
npm install - Check that files are being watched correctly
- Try refreshing the page manually
License
ISC