wire:model
The wire:model directive creates two-way data binding between form inputs and component data properties. As users type or interact with form elements, the values are automatically synchronized with your server-side data, enabling reactive forms without manual event handling.
Basic Usage
This user profile form demonstrates wire:model with various input types and live updating:
// wires/UserProfile.bx
class extends="cbwire.models.Component" {
data = {
"name": "",
"email": "",
"bio": "",
"notifications": true,
"preferences": [],
"country": ""
};
function save() {
// Save user profile
sleep(1000);
}
}// wires/UserProfile.cfc
component extends="cbwire.models.Component" {
data = {
"name" = "",
"email" = "",
"bio" = "",
"notifications" = true,
"preferences" = [],
"country" = ""
};
function save() {
// Save user profile
sleep(1000);
}
}What wire:model Does
When you add wire:model to an input, CBWIRE automatically:
Binds Data: Creates two-way binding between input values and component properties
Syncs Changes: Updates server data when users interact with form elements
Preserves State: Maintains input values across component re-renders
Handles Types: Automatically manages different input types (text, checkbox, select, etc.)
Available Modifiers
The wire:model directive supports these modifiers:
Live:
.live- Sends updates as user types (with 150ms debounce)Blur:
.blur- Only sends updates when input loses focusChange:
.change- Only sends updates on change eventLazy:
.lazy- Prevents server updates until an action is calledDebounce:
.debounce.Xms- Customizes debounce timing (e.g.,.debounce.500ms)Throttle:
.throttle.Xms- Throttles network requests by X millisecondsNumber:
.number- Casts text input to integer on serverBoolean:
.boolean- Casts text input to boolean on serverFill:
.fill- Uses initial HTMLvalueattribute during page load
Combine modifiers as needed: wire:model.live.debounce.500ms="username"
Input Types
Text Inputs
Textarea
Don't initialize textarea content with the property value in the template:
Single Checkbox
The checkbox will be checked if the data property is true, unchecked if false.
Multiple Checkboxes
Radio Buttons
Select Dropdowns
Livewire automatically adds the selected attribute to the matching option.
Dynamic Select Options
Dependent Dropdowns
Use wire:key to ensure dependent dropdowns update properly:
Multi-Select Dropdowns
Was this helpful?