CBWIRE
v4.x
v4.x
  • Introduction
  • How It Works
  • Getting Started
  • Configuration
  • Releases
    • What's New With 4.1
    • What's New With 4.0
    • What's New With 3.2
    • What's New With 3.1
    • What's New With 3.0
    • What's New With 2.2
    • What's New With 2.1
    • What's New With 2.0
  • Resources
  • Upgrading from CBWIRE 3.x
  • Upgrading from CBWIRE 2.x
  • CBWIRE CLI
  • The Essentials
    • Components
    • Templates
    • Data Properties
    • Computed Properties
    • Data Binding
    • Actions
    • Events
    • Nesting Components
    • Lifecycle Methods
    • JavaScript
    • Testing
  • Features
    • Single-file Components
    • Alpine.js
    • Lazy Loading
    • Form Validation
    • File Uploads
    • Query String
    • Redirecting
    • WireBox
  • Template Directives
    • wire:click
    • wire:confirm
    • wire:dirty
    • wire:ignore
    • wire:init
    • wire:key
    • wire:loading
    • wire:model
    • wire:navigate
    • wire:offline
    • wire:poll
    • wire:stream
    • wire:submit
    • wire:transition
  • Advanced
    • Troubleshooting
Powered by GitBook
On this page
  • Overview
  • Removing Elements
  • Targeting Properties
  • Toggling Classes

Was this helpful?

Export as PDF
  1. Template Directives

wire:dirty

Previouswire:confirmNextwire:ignore

Last updated 7 months ago

Was this helpful?

Overview

You can use wire:dirty with to display elements when have been updated on the client side but not the server side.

// ./wires/MyForm.cfc
component extends="cbwire.models.Component" {
    data = {
        "name": "",
        "email": ""
    };
    function submit() {
        // Do something useful here
    }
}
<!--- ./wires/myform.cfm --->
<form wire:submit="submit">
    <input type="text" wire:model="name">
    <input type="email" wire:model="email">
    <button type="submit">Submit</button>
    <div wire:dirty>
        Be sure to click submit. 👀
    </div> 
</form>

As the user begins typing in the name or email field, CBWIRE will detect the data properties that have changed on the client side and display a reminder to click submit. After the user clicks submit, the data properties are synchronized, and the reminder is removed.

Removing Elements

You can invert the behavior of wire:dirty by using the .remove modifier:

<div>
    <div wire:dirty.remove>Data is synced.</div>
</div>

Targeting Properties

You can target specific data properties using wire:dirty and wire:target.

<!--- ./wires/myform.cfm --->
<form wire:submit="submit">
    <input type="text" wire:model="name">
    <div wire:dirty wire:target="name">Unsaved name changes...</div>
    <button type="submit">Update</button>
</form>

Toggling Classes

You can toggle classes on elements using wire:dirty.class.

<input wire:model="name" wire:dirty.class="border-yellow-500">

When the user types into the name field, a yellow border is displayed, letting the user know the changes have not been saved.

wire:model
data properties