DocsState & inputs · FQL
On this page

Read and update state

Use nested state and frontbacked.js to complete a form.

Before you begin: Derive display values.

Nested State

State objects can be nested.

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

Nested state is declared like a JSON object with extra FQL powers. Keep object keys quoted and FQL expressions as quoted string values when you can; the {STATE} parser reports malformed syntax with its location, while Frontbacked.init({ state }) uses normal JavaScript object syntax. Nested paths are read with $state.form.name, $state.form.email, $state.summary.name, $state.summary.tags[0], and so on.

Reading and Writing State from JavaScript

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

Frontbacked.state.get(path) returns undefined when the path moves through a missing object or array. It does not throw for missing data.

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

It does throw when a path tries to keep reading through a defined non-object value.

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

Array indexes can be read or written with square brackets or dot indexes. These point to the same state path:

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

Frontbacked.state.set(path, value) writes one path. Frontbacked.state.set(object) merges an object into the current state and re-renders FQL bindings.

Full Form State Example

index.html

This combines input events, a defaulted checkbox state, multiple sources, submit handling, and derived display state.

Unique array items

In Frontbacked.state.check(), use unique: true to reject repeated whole items, or uniqueBy to compare selected fields in an array of objects:

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

A single path such as uniqueBy: "productId" compares one field. A list compares the combination of all selected fields. Nested paths such as variant.size are supported. Every selected field must contain a value; missing values, null, and empty text produce an error. Zero and false are valid keys.

Validation compares normalized item values. Object property order is ignored recursively, while array order, value types, case and whitespace remain significant unless you explicitly normalize the strings. Duplicates produce validation feedback; items are never removed automatically. Schemas loaded with Frontbacked.schemas.post() carry the same uniqueness rules from FRL.