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
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_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 bestr
orbytes
,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.