CBWIRE
InstallSource CodeIssuesSupport
v3.x
v3.x
  • Introduction
  • Getting Started
  • Configuration
  • How It Works
  • Release History
    • 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
  • Examples
    • Contact Form
    • Multi-select Input
    • File Upload
  • Resources
  • The Essentials
    • Components
    • Templates
    • Data Properties
    • Computed Properties
    • Actions
    • Events
    • Lifecycle Methods
    • JavaScript
    • Testing
  • Wire Features
    • Validation
    • File Uploads
    • Query String
    • Redirecting
    • WireBox
  • Template Features
    • Directives
    • Loading States
    • Polling
    • Prefetching
    • Offline State
    • Defer Loading
    • Dirty State
  • Integrations
    • ContentBox CMS
    • SPAs with Turbo
    • AlpineJS
Powered by GitBook
On this page
  1. Wire Features

Query String

Set your data properties with incoming query string values.

It can sometimes be helpful to update the browser's query string when your component's state changes.

Let's say we are building a component to search articles.

<!--- ./wires/SearchArticles.cfm --->
<cfscript>
    data = {
        "search": ""
    };
</cfscript>

<cfoutput>
    <div>
        <input wire:model="search" type="search" placeholder="Search articles...">
    </div>
</cfoutput>

We can automatically populate the search property above from the URL query string by adding a queryString array to our component.

queryString = [ "search" ];
<!-- ./wires/SearchArticles.cfm -->
<cfscript>
    queryString = [ "search" ];

    data = {
        "search": ""
    };
</cfscript>

<cfoutput>
    <div>
        <input wire:model="search" type="search" placeholder="Search articles...">
    </div>
</cfoutput>

Now when we access the page with 'search' included in the query string (/search-articles?search=some+string), the search property will have a default value of "some string".

In addition to this, when the user starts typing into our search field, the URL displayed in the browser will be instantly updated.

PreviousFile UploadsNextRedirecting

Last updated 1 year ago