back_button Widget

Use a back button widget to customize the back button of a nav_page. Assign the widget to the start attribute of the nav page.

Back button widgets cannot appear anywhere else.

Attributes:

  • actions: [action]
    • Required
    • A list of actions to perform when the user taps the back button.
    • When the list is empty, the button is disabled.

RPC Example

In this example, the back button performs an rpc action.

If the RPC fails, the page will not pop. The user may become frustrated and stuck. See section 3 "User control and freedom" of Nielsen Norman's 10 Usability Heuristics for User Interface Design.

screenshot

# Ruby
nav_page(
    title: "Edit Note",
    start: back_button(actions: [rpc("/save_note"), pop]),
  ) {
  scroll {
    column(widgets: [
      textfield(var_name: "note"),
    ])
  }
}
#![allow(unused)]
fn main() {
// Rust
nav_page("Edit Note", scroll(column(textfield("note"))))
.with_start(back_button([rpc("/save_note"), pop()]))
}

Disabled

To disable the back button, set the actions to an empty list.

The user may become frustrated. See section 3 "User control and freedom" of Nielsen Norman's 10 Usability Heuristics for User Interface Design.

screenshot

# Ruby
nav_page(title: "Disabled Back Button", start: back_button(actions: [])) {
  scroll {
    column(widgets: [
      text("text"),
    ])
  }
}
#![allow(unused)]
fn main() {
// Rust
nav_page("Removed Back Button", scroll(form(text("text"))))
.with_start(back_button([]))
}