Client Attributes
WSX uses HTML attributes to define interactive behavior in your web applications. These attributes control how elements trigger WebSocket requests and handle responses.Core Attributes
wx-send
Defines the action to send to the server when triggered:wx-target
Specifies the element to update with the response:wx-trigger
Defines when to send the request:Content Attributes
wx-swap
Controls how content is swapped:wx-config
Configures WSX behavior for a container:Data Attributes
Form Data
WSX automatically captures form data:Custom Data
Add custom data withdata-wx-*
attributes:
Dynamic Data
Use JavaScript to set dynamic data:Advanced Attributes
wx-headers
Add custom headers to requests:wx-validate
Client-side validation before sending:wx-confirm
Show confirmation dialog:wx-loading
Show loading state during request:Conditional Attributes
wx-if
Conditionally enable WSX behavior:wx-unless
Conditionally disable WSX behavior:Event Attributes
wx-on-*
Handle WSX events:Multiple Actions
Different Triggers
Conditional Actions
Real-World Examples
Search Interface
Auto-Save Form
Interactive List
File Upload
Attribute Inheritance
Container Attributes
Child elements inherit container attributes:Override Inheritance
Dynamic Attributes
JavaScript Manipulation
Template Systems
Best Practices
- Use Semantic HTML: Build on standard HTML elements and forms
- Progressive Enhancement: Ensure functionality works without JavaScript
- Specific Targets: Use specific selectors to avoid conflicts
- Validate Data: Use
wx-validate
for client-side validation - Handle Errors: Use
wx-on-error
for error handling - Loading States: Use
wx-loading
for better UX - Accessibility: Ensure interactive elements are accessible
Common Patterns
Form Validation
Progressive Loading
Real-time Updates
Next Steps
- Learn about Client Triggers for event handling
- Explore Client Events for response handling
- Understand Client Configuration for global settings