Skip to main content

exec_attr

Function exec_attr 

Source
pub fn exec_attr(attr: &str, to: Option<&str>) -> Result<(), Error>
Expand description

Runs the JS command chain stored in a data-* attribute.

The attribute named attr on the element at to (or the LiveView root when None) must contain a JS command chain encoded by Phoenix.LiveView.JS. That chain is then executed in place.

Mirrors Phoenix.LiveView.JS.exec/2, which is typically used to stash a pre-built command on an element (for example data-show={JS.show(...)}) and trigger it later without re-sending it over the wire.

§Errors

Returns Error::NoLiveSocket, Error::NoLiveViewRoot, or Error::ExecFailed. See Error.

§Example

use wasm_liveview as lv;

// Run the command chain stored in `#modal`'s `data-show` attribute.
lv::exec_attr("data-show", Some("#modal"))?;