Triggers
Triggers define when and how client-side events are sent to your WSX server. They provide sophisticated control over event timing, conditions, and behavior.Basic Triggers
Default Triggers
Without specifyingwx-trigger
, elements use default triggers:
Explicit Triggers
Specify triggers using thewx-trigger
attribute:
Trigger Events
Common Events
click
- Mouse clickssubmit
- Form submissionsinput
- Input value changeschange
- Input value changes (on blur)keyup
- Key release eventskeydown
- Key press eventsmouseenter
- Mouse enters elementmouseleave
- Mouse leaves elementfocus
- Element gains focusblur
- Element loses focus
Examples
Trigger Modifiers
Throttling
Limit the frequency of requests:Debouncing (Queue)
Delay requests until activity stops:Delays
Add delays before sending requests:Conditional Triggers
Key Conditions
Trigger only on specific keys:Change Detection
Only trigger when values actually change:Once Modifier
Trigger only once:Multiple Triggers
Combining Triggers
Use multiple events for the same action:Different Actions
Different triggers for different actions:Advanced Trigger Patterns
Conditional Logic
Form Validation
Progressive Enhancement
Trigger Timing
Immediate Triggers
Delayed Triggers
Throttled Triggers
Debounced Triggers
Real-World Examples
Live Search
Auto-Save Form
Keyboard Shortcuts
Progressive Loading
Custom Triggers
JavaScript Events
Programmatic Triggers
Best Practices
- Choose Appropriate Events: Use the right trigger for the user interaction
- Throttle Heavy Operations: Use throttling for expensive operations like search
- Debounce User Input: Use queue for final input validation
- Provide Feedback: Show loading states for delayed actions
- Consider Accessibility: Ensure triggers work with keyboard navigation
- Progressive Enhancement: Provide fallbacks for critical functionality
Next Steps
- Learn about Swaps for content replacement
- Explore Out-of-Band Updates for multiple element updates
- Understand Client Configuration for trigger customization