arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Directives

CBWIRE's powerful directives allow you to listen for client side events, invoke actions, bind to data properties, and more.

hashtag
Core Directives

The following Directives can be added to your Templates and instruct CBWIRE how and when to update the Wire.

hashtag
wire:key

Define a key name foo for the element. This provides a reference point for the Livewire DOM diffing system. Useful for adding/removing elements and keeping track of lists.

hashtag
wire:click

Listens for a click event and invokes the foo .

circle-info

You will want to add the .prevent to ensure that the browser doesn't follow the link.

hashtag
wire:click.prefetch

Listens for a mouseEnter event and then prefetches the result of the foo . If the element is then clicked, it will swap in the prefetched result without any extra request. If it's not clicked, the cached results will be thrown away.

hashtag
wire:submit

Listeners for a submit event on a form.

circle-info

You will want to add the .prevent to ensure that the browser doesn't submit the form.

hashtag
wire:keydown

Listens for a keyDown event and invokes the foo .

hashtag
wire:keydown.enter

Listens for a keyDown event when the user hits enter and invokes the foo .

hashtag
wire:foo

Listens for a foo event and invokes the bar .

circle-check

You can listen to any JS event, not just those defined by Livewire.

hashtag
wire:model

Provided you have data[ "foo" ] defined in your , this creates a one-to-one model binding. Any time the element is updated, the value is synchronized.

hashtag
wire:model.debounce

The same as wire:model="foo" except that all input events to the element will be debounced for the specified duration. Defaults to 150 milliseconds. Useful for reducing XHR background requests during user input. You can set the milliseconds value to any numeric value.

hashtag
wire:model.defer

Creates a one-to-one model binding with data[ "foo" ] in your but defers any XHR updates until an is performed. Useful for reducing XHR requests.

hashtag
wire:model.lazy

Creates a one-to-one model binding with data[ "foo" ] in your but will not perform an XHR updates until an onBlur event is emitted. Useful for reducing XHR requests.

circle-check

If your input field does not require immediate updating ( such as for instant form validation), we highly recommended you used the lazy modifier to reduce the number of XHR requests .

hashtag
wire:poll

Performs an XHR request to re-render the elements based on a set interval. An interval can be specified in both seconds or milliseconds. You can also specify an that you want to invoke.

hashtag
wire:init

Invokes the foo on your immediately after it's rendered on the page.

hashtag
wire:loading

Hides the HTML element by default and makes it visible when XHR requests are performed.

hashtag
wire:loading.class

Adds the foo class to the HTML element while XHR requests are in transit.

hashtag
wire:loading.class.remove

Removes the foo class from the HTML element while XHR requests are in transit.

hashtag
wire:loading.attr

Adds the disabled="true" attribute while XHR requests are in transit.

hashtag
wire:dirty

Hides the HTML element by default and makes it visible when the element's state has changed since the latest XHR request.

hashtag
wire:dirty.class

Adds the foo class to the HTML element when the element's state has changed since the latest XHR request.

hashtag
wire:dirty.class.remove

Removes the foo class from the HTML element when the element's state has changed since the latest XHR request.

hashtag
wire:dirty.attr

Adds the disabled="true" attribute when the element's state has changed since the latest XHR request. Used in addition to wire:target.

hashtag
wire:target

Provides scoping for wire:loading and wire:dirty references, scoped to a specific .

hashtag
wire:ignore

Instructs Livewire to not update the element or any child elements when updating the DOM. Useful when using third-party JavaScript libraries.

hashtag
wire:ignore.self

Instructs Livewire to not update the element but DOES allow updates to any child elements when updating the DOM.

hashtag
wire:offline

See

hashtag
Event Modifiers

CBWIRE Directives sometimes offer "modifiers" to add extra functionality to an event. Here are the available modifiers that can be used with any event.

Modifier

hashtag
Keydown Modifiers

To listen for specific keys on keydown events, you can provide the name of the key as a modifier. You can use any valid key names exposed via as modifiers by converting them to kebab-case.

Here is a quick list of some common ones you may need:

Native Browser Event
Livewire Modifier

In the above example, the foo will only be called if event.key is equal to 'PageDown'.

debounce.300ms

Adds an Xms debounce to the handling of the action.

Tab

tab

ArrowRight

arrow-right

stop

Equivalent of event.stopPropagation()

prevent

Equivalent of event.preventDefault()

self

Only triggers an action if the event was triggered on itself. This prevents outer elements from catching events that were triggered from a child element. (Like often in the case of registering a listener on a modal backdrop)

Backspace

backspace

Escape

escape

Shift

shift

Action
modifier
Action
modifier
Action
Action
Action
Data Properties
Data Properties
Action
Data Properties
Action
See Polling
Action
Wire
Action
Offline State
KeyboardEvent.keyarrow-up-right
Action
<div wire:key="foo"></div>
<button wire:click="foo">...</button>

<a href="" wire:click.prevent="foo">Click here</a>
<button wire:click.prefetch="foo">...</button>
<form wire:submit.prevent="someAction">
    <button type="submit">Submit Form</button>
</form>
<input wire:keydown="foo" type="text">
<input wire:keydown.enter="foo" type="text">
<select wire:foo="bar"></select>
<input wire:model="foo" type="text">
<input wire:model.debounce.1s="foo" type="text">
<input wire:model.debounce.500ms="foo" type="text">
<input wire:model.defer="foo" type="text">
<input wire:model.lazy="foo" type="text">
<div wire:poll></div>
<div wire:poll.5s></div>
<div wire:poll.5000ms></div>
<div wire:poll.5s="fooMethod"></div>
<div wire:init="foo"></div>
<span wire:loading><img src="spinner.gif"></span>
<div wire:loading.class="highlight"></div>
<div wire:loading.class.remove="highlight" class="highlight"></div>
<button wire:loading.attr="disabled">...</button>
<div wire:dirty="foo">...</div>
<div wire:dirty.class="highlight">...</div>
<div wire:dirty.class.remove="highlight" class="highlight">...</div>
<button wire:dirty.attr="disabled">...</div>
<button wire:dirty.attr="disabled" wire:target="foo">...</div>
<div wire:ignore></div>
<div wire:ignore.self></div>
<a href="" wire:click.prevent="someAction">Click here</a>
<input wire:keydown.page-down="foo">