NAME
Chandra::Event - Event object for element handlers
SYNOPSIS
# In an element handler:
onclick => sub {
my ($event, $app) = @_;
print "Event type: ", $event->type, "\n";
print "Target ID: ", $event->target_id, "\n";
print "Value: ", $event->value, "\n";
}
DESCRIPTION
Chandra::Event wraps the event data sent from JavaScript when a DOM event fires. It is passed as the first argument to element event handlers (onclick, onchange, etc.).
CONSTRUCTOR
new
my $event = Chandra::Event->new(\%data);
Creates a new event from a hashref. Typically called internally by Chandra::Bind during dispatch, not by user code.
The %data hash may contain: type, targetId, targetName, value, checked, key, keyCode, and any custom fields.
METHODS
type
The event type (click, change, keyup, submit, etc.).
target_id
The ID attribute of the element that fired the event.
target_name
The name attribute of the element.
value
The current value (for input/select elements).
checked
Boolean checked state (for checkboxes).
key
The key pressed (for keyboard events).
key_code
The numeric key code (for keyboard events).
data
my $val = $event->data($key);
Access custom data passed with the event or data-* attributes.
get
my $val = $event->get($key);
Access any arbitrary field from the raw event data by key.