DOM and component events: tp.On() and Component.On()
This demo compares native browser DOM events with Tripous component events.
A DOM event comes from a browser EventTarget, such as a button or input element.
A Tripous component event comes from a tp.Object descendant, such as
tp.Button or tp.TextBox.
Use tp.On(element, "click", handler) when subscribing to a native DOM event.
The handler receives the native browser event object. Use Component.On("EventName", handler)
when subscribing to a Tripous component event. The handler receives a tp.EventArgs
object with EventName, Sender, and any extra event data.
Some Tripous components bridge native DOM events to component events. For example,
tp.Button listens to the DOM click event of its internal button
element and then triggers a Tripous Click event. tp.TextBox
listens to DOM input and change events and then triggers
ValueChanged.
Native DOM event with tp.On()
This button is a normal HTML button. The listener is attached with
tp.On("#NativeDomButton", "click", function (event) { ... }).
The handler receives the native browser MouseEvent.
tp.Button component event
This button is wrapped by new tp.Button("#TripousButton").
The component listens to the DOM click and then triggers its Tripous
Click event. The listener receives tp.EventArgs.
tp.TextBox ValueChanged
This input is wrapped by tp.TextBox. Typing in the input triggers
native DOM input events and the Tripous ValueChanged
component event.
Programmatic dispatch with tp.Trigger()
tp.Trigger() dispatches a native DOM event. This button triggers the
native DOM button click, the tp.Button click, and an input event on
the text box.