pub struct Press { /* private fields */ }Expand description
Behavior for on_press: call a server action, navigate, dispatch an
event, or run a script.
Button![on_press = action!(archive), "Archive"] // server action
Button![on_press = Press::from(action!(like)).input(&id), "Like"]
Button![on_press = Press::navigate("/settings"), "Settings"]
Button![on_press = Press::emit("open-cart"), "Cart"] // `nr:open-cart` event
Button![on_press = Press::open_modal("confirm"), "Delete…"] // opens `Modal![id = "confirm", ..]`After a successful action the page refreshes (see Press::no_refresh);
the element receives nr:success / nr:error events either way.
Implementations§
Source§impl Press
impl Press
Sourcepub fn action(url: impl Into<String>) -> Self
pub fn action(url: impl Into<String>) -> Self
Call the server action at url. From a reference, use
Press::from(action!(save)) (or simply on_press = action!(save)).
Client-side navigation to href.
Sourcepub fn emit(name: impl Into<String>) -> Self
pub fn emit(name: impl Into<String>) -> Self
Dispatch a bubbling nr:<name> event from the element, for your own
scripts: addEventListener("nr:open-cart", …).
Sourcepub fn open_modal(id: impl Into<String>) -> Self
pub fn open_modal(id: impl Into<String>) -> Self
Open the Modal with that id (as a modal dialog:
focus trapped, page behind inert).
Sourcepub fn close_modal() -> Self
pub fn close_modal() -> Self
Close the modal the element is inside.
Sourcepub fn script(js: impl Into<String>) -> Self
pub fn script(js: impl Into<String>) -> Self
Run a script (an onclick attribute). Trusted code only: never pass
user input. Blocked by a strict Content Security Policy.
Sourcepub fn no_refresh(self) -> Self
pub fn no_refresh(self) -> Self
Keep the page as it is after a successful action.