Skip to content
scalive
Menu
ConnectingLiveReconnectingOffline
o

JSCommands

object JSCommands

Types and extension methods for composable Phoenix LiveView client commands.

Defined by scalive.JSCommands. View source (scalive/api/src/scalive/JS.scala:15-608)

Types1

JSCommand

opaque type JSCommand >: ([Msg] =>> Nothing) <: ([Msg] =>> Any) = ([Msg] =>> List[JSCommands.Op[Msg]])

An immutable sequence of browser commands which may bind server messages of type Msg.

The type is covariant so a command with no server message, including JS, composes with commands for any LiveView message type. Use a command with typed HTML event bindings such as on.click(command), or execute client-only commands from the server with ctx.client.exec. Class, attribute, and visibility mutations use the LiveView client's patch-aware operations, so their resulting DOM state is retained across server patches. Builders do not generally validate class names, attribute names, display values, or durations; invalid values retain the browser/client's behavior.

A command containing push must be rendered as an HTML event binding. Rendering gives each push a stable binding ID and registers its typed message. Encoding such a command directly, or sending it through ctx.client.exec, has no HTML binding scope and leaves the push unresolved; the encoded placeholder is not a usable server event binding.

Type parameters

Msg

the least upper bound of messages pushed by this command

Defined by scalive.JSCommands.JSCommand. View source (scalive/api/src/scalive/JS.scala:34-34)

Extension methods26

addClass

extension def addClass[Msg](ops: JSCommands.JSCommand[Msg]): JSCommands.ClassOp[Msg]

Appends a command which adds whitespace-separated class names to the selected elements.

to defaults to the element executing the command. transition may be a class string or an (transition, start, end) tuple of class strings; "" requests no transition. time is the transition duration in milliseconds and defaults to 200. blocking defaults to true, so LiveView defers concurrent UI work for the transition; use false to let it run asynchronously.

Defined by scalive.JSCommands.addClass. View source (scalive/api/src/scalive/JS.scala:101-101)

dispatch

extension def dispatch[Msg](ops: JSCommands.JSCommand[Msg])(event: String, to: DomSelector = ..., detail: Map[String, String] = ..., bubbles: Boolean = ..., blocking: Boolean = ...): JSCommands.JSCommand[Msg]

Appends a command which dispatches a DOM event to the selected elements.

The LiveView client dispatches "click" as a MouseEvent and other names as a CustomEvent. detail is included in the event detail along with a client-supplied dispatcher reference. Events bubble by default. With blocking = true, the detail also contains done; the listener must eventually call it to release the blocked UI.

Parameters

event

the DOM event name

to

the event targets, defaulting to the element executing this command

detail

string-valued custom-event detail, defaulting to no application detail

bubbles

whether the event bubbles, defaulting to true

blocking

whether to block LiveView UI work until event.detail.done() is called; defaults to false

Defined by scalive.JSCommands.dispatch. View source (scalive/api/src/scalive/JS.scala:142-158)

exec

extension def exec[Msg](ops: JSCommands.JSCommand[Msg])(attr: String, to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which executes the encoded JS command stored in an HTML attribute.

The attribute is read from each selected element and executed with that element as its command source. A missing or empty attribute causes the LiveView client to report an error.

Parameters

attr

the attribute name containing an encoded command

to

the element from which to read the attribute, defaulting to the current command source

Defined by scalive.JSCommands.exec. View source (scalive/api/src/scalive/JS.scala:170-177)

focus

extension def focus[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which focuses the selected elements.

to defaults to the element executing the command.

Defined by scalive.JSCommands.focus. View source (scalive/api/src/scalive/JS.scala:183-187)

focusFirst

extension def focusFirst[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which focuses the first focusable descendant of each selected element.

The client prefers an interactive descendant and falls back to the first focusable one. to defaults to the element executing the command.

Defined by scalive.JSCommands.focusFirst. View source (scalive/api/src/scalive/JS.scala:194-198)

hide

extension def hide[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ..., transition: |[String, Tuple3[String, String, String]] = ..., time: Int = ..., blocking: Boolean = ...): JSCommands.JSCommand[Msg]

Appends a command which hides selected elements that are currently visible.

transition accepts a class string or an (transition, start, end) tuple; "" requests no transition. time is measured in milliseconds and defaults to 200. blocking defaults to true; false allows the timed transition to proceed without blocking other LiveView UI work. to defaults to the element executing the command.

Defined by scalive.JSCommands.hide. View source (scalive/api/src/scalive/JS.scala:207-221)

ignoreAttributes

extension def ignoreAttributes[Msg](ops: JSCommands.JSCommand[Msg])(attrs: Seq[String] = ..., to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which preserves selected client-side attributes across future DOM patches.

Names may include the LiveView client's * wildcard syntax. Calling this command again replaces the ignored set for each target. It affects future patches only, so it cannot restore an attribute already changed during disconnected render. Although attrs defaults to an empty sequence, the current client expects an actual list; pass a non-empty sequence rather than relying on that default. to defaults to the element executing the command.

Defined by scalive.JSCommands.ignoreAttributes. View source (scalive/api/src/scalive/JS.scala:231-241)

popFocus

extension def popFocus[Msg](ops: JSCommands.JSCommand[Msg])(): JSCommands.JSCommand[Msg]

Appends a command which focuses the most recently pushed focus target, if one exists.

Defined by scalive.JSCommands.popFocus. View source (scalive/api/src/scalive/JS.scala:337-338)

push

extension def push[Msg](ops: JSCommands.JSCommand[Msg])[Msg2 >: Msg](event: Msg2, target: DomSelector = ..., loading: DomSelector = ..., pageLoading: Boolean = ...): JSCommands.JSCommand[Msg2]

Appends a typed event push to the server.

Unlike Phoenix's string event API, event is the Scala message delivered by the rendered event binding. HTML rendering replaces it with a stable binding ID and registers the message under that ID. This widens the command's message type as needed. Multiple pushes in one command are registered independently and retain composition order.

target = DomSelector.current omits an explicit target, allowing the source element's phx-target and normal LiveView ownership rules to apply. An explicit selector overrides that target. The source receives the normal loading state; an explicit loading selector additionally applies the event's loading class and locks matching elements until the server acknowledges the push. pageLoading defaults to false; the option is encoded, but the currently supported Phoenix client does not observe its camel-case name, so setting it does not currently trigger page-loading lifecycle events.

A push must be attached to a typed HTML event binding such as on.click(JS.push(message)). Standalone JSON encoding and ctx.client.exec cannot allocate its binding ID and therefore leave an unresolved placeholder.

Parameters

event

the Scala message to deliver to the LiveView

target

an explicit server-event target, or current to use normal source targeting

loading

additional elements which receive loading state, or current for only the source's normal loading state

pageLoading

the page-loading option, currently not observed by the supported client; defaults to false

Defined by scalive.JSCommands.push. View source (scalive/api/src/scalive/JS.scala:370-390)

pushFocus

extension def pushFocus[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which pushes a focus target onto the client's focus stack.

Pair this with popFocus to restore focus later. to defaults to the element executing the command.

Defined by scalive.JSCommands.pushFocus. View source (scalive/api/src/scalive/JS.scala:397-398)

pushNavigate

extension def pushNavigate[Msg](ops: JSCommands.JSCommand[Msg])(to: LiveLocation): JSCommands.JSCommand[Msg]

Appends a live navigation to a typed location and pushes a browser history entry.

This changes LiveViews rather than patching the current one. Requiring LiveLocation keeps normal navigation tied to route-derived, encoded destinations; use pushNavigateUnsafe only when no typed location can represent the destination.

Defined by scalive.JSCommands.pushNavigate. View source (scalive/api/src/scalive/JS.scala:249-250)

extension def pushNavigate[Msg](ops: JSCommands.JSCommand[Msg])(to: Signal[LiveLocation]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for a navigation destination.

Defined by scalive.JSCommands.pushNavigate. View source (scalive/api/src/scalive/JS.scala:253-254)

pushNavigateUnsafe

extension def pushNavigateUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: String): JSCommands.JSCommand[Msg]

Appends a live navigation to the raw href and pushes a browser history entry.

The string is passed through without route typing, validation, or normalization. "Unsafe" denotes that explicit escape from typed outbound navigation; it does not apply a different client navigation mechanism.

Defined by scalive.JSCommands.pushNavigateUnsafe. View source (scalive/api/src/scalive/JS.scala:262-263)

extension def pushNavigateUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: Signal[String]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for a raw navigation destination.

Defined by scalive.JSCommands.pushNavigateUnsafe. View source (scalive/api/src/scalive/JS.scala:266-267)

pushPatch

extension def pushPatch[Msg](ops: JSCommands.JSCommand[Msg])(to: LiveLocation): JSCommands.JSCommand[Msg]

Appends a live patch to a typed location and pushes a browser history entry.

A patch updates the current LiveView without replacing it. Use pushPatchUnsafe for raw destinations such as query-only references which cannot be represented by a full typed location.

Defined by scalive.JSCommands.pushPatch. View source (scalive/api/src/scalive/JS.scala:298-299)

extension def pushPatch[Msg](ops: JSCommands.JSCommand[Msg])(to: Signal[LiveLocation]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for a patch destination.

Defined by scalive.JSCommands.pushPatch. View source (scalive/api/src/scalive/JS.scala:302-303)

pushPatchUnsafe

extension def pushPatchUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: String): JSCommands.JSCommand[Msg]

Appends a live patch to raw href and pushes a browser history entry.

The string is passed through without route typing, validation, or normalization. This is the explicit escape hatch for destinations such as "?page=2".

Defined by scalive.JSCommands.pushPatchUnsafe. View source (scalive/api/src/scalive/JS.scala:310-311)

extension def pushPatchUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: Signal[String]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for a raw patch destination.

Defined by scalive.JSCommands.pushPatchUnsafe. View source (scalive/api/src/scalive/JS.scala:314-315)

removeAttribute

extension def removeAttribute[Msg](ops: JSCommands.JSCommand[Msg])(attr: String, to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which removes attr from the selected elements.

The client keeps this attribute mutation across subsequent DOM patches. to defaults to the element executing the command.

Defined by scalive.JSCommands.removeAttribute. View source (scalive/api/src/scalive/JS.scala:405-412)

removeClass

extension def removeClass[Msg](ops: JSCommands.JSCommand[Msg]): JSCommands.ClassOp[Msg]

Appends a command which removes whitespace-separated class names from selected elements.

to defaults to the element executing the command. transition may be a class string or an (transition, start, end) tuple of class strings; "" requests no transition. time is the transition duration in milliseconds and defaults to 200. blocking defaults to true, so LiveView defers concurrent UI work for the transition; use false to let it run asynchronously.

Defined by scalive.JSCommands.removeClass. View source (scalive/api/src/scalive/JS.scala:121-121)

replaceNavigate

extension def replaceNavigate[Msg](ops: JSCommands.JSCommand[Msg])(to: LiveLocation): JSCommands.JSCommand[Msg]

Appends a live navigation to a typed location and replaces the current history entry.

This changes LiveViews rather than patching the current one. Use replaceNavigateUnsafe only for a destination which cannot be represented by a LiveLocation.

Defined by scalive.JSCommands.replaceNavigate. View source (scalive/api/src/scalive/JS.scala:274-275)

extension def replaceNavigate[Msg](ops: JSCommands.JSCommand[Msg])(to: Signal[LiveLocation]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for replacement navigation.

Defined by scalive.JSCommands.replaceNavigate. View source (scalive/api/src/scalive/JS.scala:278-279)

replaceNavigateUnsafe

extension def replaceNavigateUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: String): JSCommands.JSCommand[Msg]

Appends a live navigation to raw href and replaces the current browser history entry.

The string is passed through without route typing, validation, or normalization.

Defined by scalive.JSCommands.replaceNavigateUnsafe. View source (scalive/api/src/scalive/JS.scala:285-286)

extension def replaceNavigateUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: Signal[String]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for raw replacement navigation.

Defined by scalive.JSCommands.replaceNavigateUnsafe. View source (scalive/api/src/scalive/JS.scala:289-290)

replacePatch

extension def replacePatch[Msg](ops: JSCommands.JSCommand[Msg])(to: LiveLocation): JSCommands.JSCommand[Msg]

Appends a live patch to a typed location and replaces the current browser history entry.

Defined by scalive.JSCommands.replacePatch. View source (scalive/api/src/scalive/JS.scala:318-319)

extension def replacePatch[Msg](ops: JSCommands.JSCommand[Msg])(to: Signal[LiveLocation]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for replacement patching.

Defined by scalive.JSCommands.replacePatch. View source (scalive/api/src/scalive/JS.scala:322-323)

replacePatchUnsafe

extension def replacePatchUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: String): JSCommands.JSCommand[Msg]

Appends a live patch to raw href and replaces the current browser history entry.

The string is passed through without route typing, validation, or normalization.

Defined by scalive.JSCommands.replacePatchUnsafe. View source (scalive/api/src/scalive/JS.scala:329-330)

extension def replacePatchUnsafe[Msg](ops: JSCommands.JSCommand[Msg])(href: Signal[String]): Signal[JSCommands.JSCommand[Msg]]

Builds a signal-backed command for raw replacement patching.

Defined by scalive.JSCommands.replacePatchUnsafe. View source (scalive/api/src/scalive/JS.scala:333-334)

setAttribute

extension def setAttribute[Msg](ops: JSCommands.JSCommand[Msg])(arg: (String, String), to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which sets an HTML attribute on the selected elements.

arg is the attribute name and value. The client keeps this attribute mutation across subsequent DOM patches. This changes an attribute, not a same-named DOM property. to defaults to the element executing the command.

Defined by scalive.JSCommands.setAttribute. View source (scalive/api/src/scalive/JS.scala:420-421)

show

extension def show[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ..., transition: |[String, Tuple3[String, String, String]] = ..., time: Int = ..., blocking: Boolean = ..., display: String = ...): JSCommands.JSCommand[Msg]

Appends a command which shows selected elements that are currently hidden.

transition accepts a class string or an (transition, start, end) tuple; "" requests no transition. time is measured in milliseconds and defaults to 200. blocking defaults to true; false allows the timed transition to proceed without blocking other LiveView UI work. The default display request uses the client's normal display value (block, with table-row and table-cell handling); another value is sent explicitly. to defaults to the element executing the command.

Defined by scalive.JSCommands.show. View source (scalive/api/src/scalive/JS.scala:432-448)

toggle

extension def toggle[Msg](ops: JSCommands.JSCommand[Msg])(to: DomSelector = ..., in: |[String, Tuple3[String, String, String]] = ..., out: |[String, Tuple3[String, String, String]] = ..., time: Int = ..., blocking: Boolean = ..., display: String = ...): JSCommands.JSCommand[Msg]

Appends a command which toggles the visibility of selected elements.

in and out each accept a class string or an (transition, start, end) tuple; "" requests no classes for that direction. time is measured in milliseconds and defaults to 200. blocking defaults to true; false lets a timed transition run without blocking other LiveView UI work. The default display request uses the client's normal display value (block, with table-row and table-cell handling); another value is sent explicitly. to defaults to the element executing the command.

Defined by scalive.JSCommands.toggle. View source (scalive/api/src/scalive/JS.scala:459-477)

toggleAttribute

extension def toggleAttribute[Msg](ops: JSCommands.JSCommand[Msg])(name: String, value: String, altValue: String = ..., to: DomSelector = ...): JSCommands.JSCommand[Msg]

Appends a command which toggles an attribute on selected elements.

With the default empty altValue, the client sets name to value when absent and removes it when present. With a non-empty altValue, it toggles between value and altValue. to defaults to the element executing the command.

Defined by scalive.JSCommands.toggleAttribute. View source (scalive/api/src/scalive/JS.scala:485-497)

toggleClass

extension def toggleClass[Msg](ops: JSCommands.JSCommand[Msg]): JSCommands.ClassOp[Msg]

Appends a command which toggles whitespace-separated class names on the selected elements.

to defaults to the element executing the command. transition may be a class string or an (transition, start, end) tuple of class strings; "" requests no transition. time is the transition duration in milliseconds and defaults to 200. blocking defaults to true, so LiveView defers concurrent UI work for the transition; use false to let it run asynchronously.

Defined by scalive.JSCommands.toggleClass. View source (scalive/api/src/scalive/JS.scala:111-111)

transition

extension def transition[Msg](ops: JSCommands.JSCommand[Msg])(transition: |[String, Tuple3[String, String, String]] = ..., to: DomSelector = ..., time: Int = ..., blocking: Boolean = ...): JSCommands.JSCommand[Msg]

Appends a temporary class transition to the selected elements.

A string supplies transition classes with empty start and end phases. A tuple supplies the (transition, start, end) class strings. Unlike the optional transitions on visibility and class commands, this command always sends a transition shape; callers should provide at least one non-empty class rather than relying on the "" default. time is measured in milliseconds and defaults to 200. blocking defaults to true; false lets the transition run without blocking other LiveView UI work. to defaults to the element executing the command.

Defined by scalive.JSCommands.transition. View source (scalive/api/src/scalive/JS.scala:509-525)