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.bxclassextends="cbwire.models.Component"{ data ={"name":"","email":"","bio":"","notifications":true,"preferences": [],"country":""};functionsave(){ // Save user profilesleep(1000);}}
// wires/UserProfile.cfccomponentextends="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
Throttle: .throttle.Xms - Throttles network requests by X milliseconds
Number: .number - Casts text input to integer on server
Boolean: .boolean - Casts text input to boolean on server
Fill: .fill - Uses initial HTML value attribute 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
By default, wire:model only sends updates when actions are performed. Use wire:model.live for real-time validation or immediate server updates as users type.