Custom Buttons
For complex interactions, default "Next" and "Back" buttons may not be sufficient. You can define custom buttons as shown below:
from abstra.forms import run, TextInput, Button
import my_api
def deal_decision(state):
if state.get("approve"):
my_api.approve(state["deal_id"])
return
if state.get("reject"):
my_api.reject(state["deal_id"])
return
return [
TextInput(label="Enter deal ID", key="deal_id")
], [Button("Approve", key="approve"), Button("Reject", key="reject")]
state = run([deal_decision])
info
- When a button is pressed, the function runs with its value set to
True
. - Since the
key
parameter is optional in the button, if it is omitted, the key in the state that is set toTrue
will be the button's label. - Returning widgets advances the page automatically.