on<event> attributes you already know from HTML — onclick, oninput, onchange, onkeydown, and any other standard event attribute. The difference is that instead of writing inline JavaScript, you provide the name of a method on your model class. Sprincul converts the attribute into a real event listener and removes it from the DOM.
How it works
WhenSprincul.init() processes a model container, it scans every element inside for on<event> attributes. For each one it finds, it:
- Reads the attribute value as a method name on your model instance.
- Removes the inline attribute from the element so it does not appear in the rendered DOM.
- Adds a real
addEventListenercall that invokes your method when the event fires. - Passes the native
Eventobject to your handler as the first argument.
eval, and no security concerns from executing strings as code. The behavior lives entirely in your model class.
Writing event handlers
Declare your event handler as a method on your model class. Sprincul wires it up automatically — you do not need to calladdEventListener yourself.
Reflect.get to look up the method by name, so spelling and capitalization both matter.
The native Event object
Your handler receives the native browserEvent object (or a subclass like InputEvent, MouseEvent, etc.) as its first argument. You can read e.target, e.currentTarget, call e.preventDefault(), and use any other standard event API.
Supported event attributes
Any standardon<event> attribute is supported. Common examples include:
| Attribute | Event type |
|---|---|
onclick | Mouse click |
oninput | Input value change |
onchange | Committed value change (blur) |
onkeydown | Key pressed |
onsubmit | Form submission |
onfocus | Element receives focus |
onblur | Element loses focus |
Event attributes reference methods on the model
Sprincul removes
on<event> attributes from the DOM after wiring the listener. This means the raw handler name will not be visible in the rendered HTML, which is the expected behavior.