Special Events
Reflex includes a set of built-in special events that can be utilized as event triggers or returned from event handlers in your applications. These events enhance interactivity and user experience. Below are the special events available in Reflex, along with explanations of their functionality:
rx.console_log
Perform a console.log in the browser's console.
When triggered, this event logs a specified message to the browser's developer console. It's useful for debugging and monitoring the behavior of your application.
rx.scroll_to
scroll to an element in the page
When this is triggered, it scrolls to an element passed by id as parameter. Click on button to scroll to download button (rx.download section) at the bottom of the page
To keep a container automatically scrolled to the bottom as new content is added — for example a chat or log view — use the component instead.
rx.redirect
Redirect the user to a new path within the application.
Parameters
path: The destination path or URL to which the user should be redirected.external: If set to True, the redirection will open in a new tab. Defaults toFalse.
When this event is triggered, it navigates the user to a different page or location within your Reflex application. By default, the redirection occurs in the same tab. However, if you set the external parameter to True, the redirection will open in a new tab or window, providing a seamless user experience.
This event can also be run from an event handler in State. It is necessary to return the rx.redirect().
rx.set_clipboard
Set the specified text content to the clipboard.
This event allows you to copy a given text or content to the user's clipboard. It's handy when you want to provide a "Copy to Clipboard" feature in your application, allowing users to easily copy information to paste elsewhere.
rx.set_clipboard also accepts state Vars, so you can copy dynamic content,
such as the current value of an input field:
rx.set_value
Set the value of a specified reference element.
With this event, you can modify the value of a particular HTML element, typically an input field or another form element.
rx.window_alert
Create a window alert in the browser.
rx.download
Download a file at a given path.
Parameters:
url: The URL of the file to be downloaded.data: The data to be downloaded. Should bestrorbytes,data:URI,PIL.Image, or any state Var (to be converted to JSON).filename: The desired filename of the downloaded file.
url and data args are mutually exclusive, and at least one of them must be provided.When the data to download is not already available at a known URL, return
rx.download from an event handler and pass the data directly: