Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Event Arguments

The event handler signature needs to match the event trigger definition argument count. If the event handler takes two arguments, the event trigger must be able to provide two arguments.

Here is a simple example:

50

The event trigger here is on_value_commit and it is called when the value changes at the end of an interaction. This event trigger passes one argument, which is the value of the slider. The event handler which is triggered by the event trigger must therefore take one argument, which is value here.

Here is a form example:

Results

{}

In this example the event trigger is the on_submit event of the form. The event handler is handle_submit. The on_submit event trigger passes one argument, the form data as a dictionary, to the handle_submit event handler. The handle_submit event handler must take one argument because the on_submit event trigger passes one argument.

When the number of args accepted by an EventHandler differs from that provided by the event trigger, an EventHandlerArgMismatch error will be raised.

Pass Additional Arguments to Event Handlers

In some use cases, you want to pass additional arguments to your event handlers. To do this you can bind an event trigger to a lambda, which can call your event handler with the arguments you want.

Try typing a color in an input below and clicking away from it to change the color of the input.

In this case, in we want to pass two arguments to the event handler change_color, the color and the index of the color to change.

The on_blur event trigger passes the text of the input as an argument to the lambda, and the lambda calls the change_color event handler with the text and the index of the input.

When the number of args accepted by a lambda differs from that provided by the event trigger, an EventFnArgMismatch error will be raised.

Events with Partial Arguments (Advanced)

Added in v0.5.0

Event arguments in Reflex are passed positionally. Any additional arguments not passed to an EventHandler will be filled in by the event trigger when it is fired.

The following two code samples are equivalent: