Skip to main content

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:
Sends:

Custom Data

Add custom data with data-wx-* attributes:
Sends:

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

  1. Use Semantic HTML: Build on standard HTML elements and forms
  2. Progressive Enhancement: Ensure functionality works without JavaScript
  3. Specific Targets: Use specific selectors to avoid conflicts
  4. Validate Data: Use wx-validate for client-side validation
  5. Handle Errors: Use wx-on-error for error handling
  6. Loading States: Use wx-loading for better UX
  7. Accessibility: Ensure interactive elements are accessible

Common Patterns

Form Validation

Progressive Loading

Real-time Updates

Next Steps